
チュートリアル
Himi LiProduct Manager at EvoLink10 分
GLM-5.4の使い方:初めてのAPI呼び出しから画像を使ったUI修正まで
EvoLinkでGLM-5.4を呼び出し、スクリーンショットとHTML、CSSを送り、モバイルの決済ボタンを修正する手順です。
目次
EvoLinkのChat Completions APIでGLM-5.4を
glm-5.4 として利用できます。EvoLink APIキーで短いテキストを送ったら、スクリーンショットと、その画面を生成したコードを一緒に送ります。この例では、幅 390 CSSピクセルでヘルプボタンが Place order の右端に重なります。CSSパッチを依頼し、修正後に両方のボタンへクリックが届くことを確認します。 EvoLink APIキーを取得テキストだけのリクエストを送る
EvoLink APIキー、
curl、jq が必要です。手順3ではPython 3も使います。コマンドを実行するシェルに EVOLINK_API_KEY を設定します。どちらの例も https://api.evolink.ai/v1/chat/completions に送り、Bearer認証ヘッダーにキーを含めます。 APIキーの管理curl --silent --show-error --fail-with-body \
https://api.evolink.ai/v1/chat/completions \
-H "Authorization: Bearer ${EVOLINK_API_KEY:?Set EVOLINK_API_KEY}" \
-H 'Content-Type: application/json' \
--data '{
"model": "glm-5.4",
"stream": false,
"reasoning_effort": "low",
"messages": [
{ "role": "user", "content": "Reply with just the word READY." }
]
}' \
-o text-response.json &&
jq -e '{model, answer: .choices[0].message.content, usage}
| select((.answer // "") | length > 0)' text-response.jsonAPIが成功ステータスを返し、
choices[0].message.content に応答があれば疎通確認は完了です。ここで期待される短い応答は READY です。model は接続先が返すモデル名です。画像付きリクエストとの比較に usage を残します。 EvoLinkの応答例モバイル表示で重なりを再現する
以下を
checkout.html として保存します。ブラウザで開き、レスポンシブ表示を 390 × 540 CSSピクセルに設定します。ヘルプが注文ボタンの右端に重なります。1280 × 720 では、二つのボタンは別の領域にあります。<!doctype html>
<html lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Checkout overlap example</title>
<style>
body { margin: 0; background: #f4f6fa; color: #182235; font: 16px system-ui, sans-serif; }
main { max-width: 26rem; margin: 48px auto; padding: 0 16px; }
h1 { margin: 0 0 24px; }
.summary { padding: 20px; border: 1px solid #dae0eb; border-radius: 12px; background: white; }
.summary p:first-child { margin-top: 0; }
.summary p:last-child { margin-bottom: 0; }
.actions { position: fixed; inset: auto 16px 24px; display: grid; max-width: 26rem; margin-inline: auto; }
button { font: inherit; font-weight: 600; cursor: pointer; }
.place-order { width: 100%; min-height: 52px; border: 0; border-radius: 10px; background: #1742bf; color: white; }
.help-bubble { position: fixed; right: 16px; bottom: 16px; z-index: 2; width: 112px; min-height: 44px; border: 0; border-radius: 24px; background: #17243d; color: white; }
</style>
<main>
<h1>Checkout</h1>
<section class="summary" aria-label="Order summary">
<p>Travel mug × 1</p>
<p><strong>Total $24.00</strong></p>
</section>
<p id="status" role="status"></p>
</main>
<div class="actions">
<button class="place-order" type="button">Place order</button>
<button class="help-bubble" type="button">Need help?</button>
</div>
<script>
const statusLine = document.querySelector("#status");
document.querySelector(".place-order").onclick = () => { statusLine.textContent = "Order button clicked"; };
document.querySelector(".help-bubble").onclick = () => { statusLine.textContent = "Help button clicked"; };
</script>
</html>390pxのスクリーンショットを
checkout-390.png として checkout.html と同じフォルダーに保存するか、同じサイズで撮り直します。静的なサンプル画面で、ボタンはどちらがクリックされたかを表示します。
スクリーンショットとソースを送る
画像でどの要素が隠れたかが分かります。ソースはセレクター、位置、重なり順を示し、CSSの変更案に必要です。以下の指示を同じフォルダーに
repair-prompt.txt として保存します。The attached screenshot is checkout.html at a viewport of 390 × 540 CSS pixels.
The Need help button covers the right edge of Place order.
Use the screenshot and the source below to explain which CSS rules cause the overlap.
Return one minimal CSS-only unified diff for checkout.html. Keep both buttons
visible and clickable at 390 px, with no horizontal overflow. Preserve the fixed
bottom-right help position and the centered action at 1280 px. Keep both labels
and click handlers. Finish with instructions for checking the right edge of
Place order, the help button, and the desktop layout.PNGをBase64のデータURLとして
image_url ブロックに含めます。EvoLinkが取得できる公開画像URLも使えます。GLM-5.4では推論は常に有効で、reasoning_effort は low、high、max に対応します。この例は high を使い、推論と最終回答で出力予算8,192トークンを共有します。python3 - <<'PY' > screenshot-request.json
import base64
import json
from pathlib import Path
image = base64.b64encode(Path("checkout-390.png").read_bytes()).decode("ascii")
prompt = Path("repair-prompt.txt").read_text(encoding="utf-8")
source = Path("checkout.html").read_text(encoding="utf-8")
print(json.dumps({
"model": "glm-5.4",
"stream": False,
"reasoning_effort": "high",
"max_tokens": 8192,
"messages": [{
"role": "user",
"content": [
{"type": "text", "text": f"{prompt}\n\ncheckout.html:\n{source}"},
{"type": "image_url", "image_url": {"url": f"data:image/png;base64,{image}"}},
],
}],
}))
PY
curl --silent --show-error --fail-with-body \
https://api.evolink.ai/v1/chat/completions \
-H "Authorization: Bearer ${EVOLINK_API_KEY:?Set EVOLINK_API_KEY}" \
-H 'Content-Type: application/json' \
--data-binary @screenshot-request.json \
-o screenshot-response.json &&
jq -e '{model, finish_reason: .choices[0].finish_reason,
answer: .choices[0].message.content, usage}
| select((.answer // "") | length > 0)' screenshot-response.jsonanswer から修正案を読み取ります。EvoLinkではメディアを入力トークンとして課金するため、usage.prompt_tokens は処理済み画像、指示、ソースを含みます。completion_tokens は推論を含む出力用量です。prompt_tokens_details.cached_tokens があればキャッシュで処理したトークン数が分かります。テキストだけの場合との差には、新しい指示とコードの分も含まれます。 EvoLinkのAPI利用状況パッチを適用して動作を確認する
差分を確認して、ローカルのファイルに適用します。狭い画面では両方のボタンが右下を占めます。ヘルプ側の
z-index が上なので、重なった部分のクリックを受け取ります。参考修正は、狭いときだけボタンを別の行に配置するCSSです。既存スタイルの後ろに追加して、提案と比較できます。@media (max-width: 720px) {
.actions { gap: 8px; }
.help-bubble { position: static; justify-self: end; }
}| 確認 | 期待する結果 |
|---|---|
| 390 × 540、注文ボタンの右端から内側に12px、縦方向の中央をクリック | Order button clicked。修正前は同じ相対位置をクリックするとヘルプが反応します。 |
| 390 × 540、ヘルプをクリック | Help button clicked。両ボタンが表示され、重なりや横スクロールはありません。 |
| 1280 × 720、両ボタンをクリック | それぞれの状態が表示されます。注文ボタンは横方向の中央、ヘルプは右端と下端から各16pxに固定されたままです。 |
参考CSSは記事用に作成した例です。クリック確認はChromiumで行いました。
幅390 pxの決済画面で、重なった部分をクリックすると最初はヘルプが反応します。チュートリアルの CSS 修正例を適用すると、Place order と Need help? がそれぞれの状態を表示します。動画では、この修正例をブラウザーで検証する様子を確認できます。
よくあるエラーと確認方法
- テキストリクエストが失敗する。
text-response.jsonのエラーを開きます。EVOLINK_API_KEYの値が有効なEvoLinkキーか、リクエスト本文がglm-5.4を指定しているかを確認します。 - テキストは成功するが、画像は失敗する。 ファイルがPNGで、URLが
data:image/png;base64,から始まることを確認します。画像をホストした場合は、Cookieやログインなしで元画像を取得できるか調べます。 - 差分が途中で途切れる。
finish_reasonを確認します。長さの上限に達した場合は無関係なソースを削るか、出力予算を調整します。choices[0].message.contentの差分を読み、ブラウザの確認手順を実行します。
自分のスクリーンショットと対応するコンポーネントでも、同じ方法で試せます。 GLM-5.4の利用先と課金方式
別の課題を試す場合は、GLM-5.4の対応入力形式を確認してください。すでにコーディング CLI を使っているなら、EvoLink ゲートウェイの設定手順を参照できます。GLM-5.4のベンチマークは比較課題を選ぶときの参考になります。


