> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.beatapi.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.beatapi.io/_mcp/server.

# Gemini 3.6 Flash API

> Gemini 3.6 Flash を正確なモデル ID で呼び出し、ネイティブ形式のレスポンスを取得する方法を説明します。

Gemini 3.6 Flash を呼び出すには `model: "gemini-3.6-flash"` を指定します。以下の例では OpenAI Chat Completions を使って同期リクエストを送信します。

以下は実装例であり、実際のモデル出力を記録したものではありません。キーはサーバーの環境変数 `BEATAPI_API_KEY` に保存し、cURL の例では `<BEATAPI_API_KEY>` を自分のキーに置き換えてください。ブラウザー側のコードにキーを含めないでください。

## リクエストの送信

`POST https://api.beatapi.io/v1/chat/completions`

サーバー側のプロジェクトに `openai` をインストールしてください。

```typescript
import OpenAI from "openai";

const apiKey = process.env.BEATAPI_API_KEY;
if (!apiKey) throw new Error("Set BEATAPI_API_KEY in your server environment.");

const client = new OpenAI({
  apiKey,
  baseURL: "https://api.beatapi.io/v1",
});

const completion = await client.chat.completions.create({
  model: "gemini-3.6-flash",
  max_tokens: 2048,
  messages: [{ role: "user", content: "Classify the following support ticket using exactly one label: account_access, billing, or product_defect. Return the label and a brief reason. Ticket: I reset my password, but the new password still does not let me sign in." }],
});

const choice = completion.choices[0];
if (!choice || choice.finish_reason !== "stop") {
  throw new Error(`Handle the finish reason before accepting the result: ${choice?.finish_reason}`);
}
const text = choice.message.content;
if (typeof text !== "string" || !text.trim()) {
  throw new Error("The response contains no text answer.");
}
console.log(text);
console.log({ id: completion.id, model: completion.model, usage: completion.usage });
```

`max_tokens: 2048` はこのリクエストの推論と画面に表示される回答を合わせた予算であり、モデルの最大上限ではありません。実際の出力使用量を確認し、HTTP 200 だけで結果を受け入れるのではなく、途中で切れた回答を適切に処理してください。

### cURL

```bash
curl --request POST \
  --url https://api.beatapi.io/v1/chat/completions \
  --header 'Authorization: Bearer <BEATAPI_API_KEY>' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "gemini-3.6-flash",
  "max_tokens": 2048,
  "messages": [
    {
      "role": "user",
      "content": "Classify the following support ticket using exactly one label: account_access, billing, or product_defect. Return the label and a brief reason. Ticket: I reset my password, but the new password still does not let me sign in."
    }
  ]
}'
```

## 結果の取得と検証

`choices[0].message.content` から回答を取得し、実際の `finish_reason` と `usage` を確認してください。この例では `stop` を受け入れます。回答が途中で切れた場合やツール呼び出しが返った場合は、アプリケーション側で別途処理が必要です。チケットの振り分けに使う前に、返されたラベルが許可したラベルのいずれかであることを検証してください。

HTTP 200 が返っても、回答がタスクの要件を満たしているとは限りません。アプリケーション側で内容を検証してください。これらのテキストリクエストは直接結果を返すため、`/v1/tasks` をポーリングする必要はありません。

`GET /v1/models` でアカウントが利用できるモデル ID を確認してください。この最小構成の例は、追加の推論設定、サンプリング、キャッシュ制御、ホスト型ツール設定への対応を示すものではありません。