StarMagicStarMagic
日本語
简体中文简繁體中文繁EnglishEN日本語日EspañolES한국어KO
統合ガイド
Gemini 2.5 Flash - OpenAI SDK - 快速开始Gemini 2.5 Flash - OpenAI SDK - API Reference
StarMagicStarMagic
日本語
简体中文简繁體中文繁EnglishEN日本語日EspañolES한국어KO
テキストGeminiGemini.2.5.FlashOpenai.Sdk

Gemini 2.5 Flash - OpenAI SDK - APIリファレンス

  • OpenAI SDK形式でgemini-2.5-flashモデルを呼び出し
  • 同期処理モード、会話内容をリアルタイムで返却
  • プレーンテキスト会話: シングルターンまたはマルチターンのコンテキスト対話、コードサンプルのsimple_textおよびmulti_turnの例を参照
  • システムプロンプト: AIのロールと動作をカスタマイズ、コードサンプルのsystem_promptの例を参照
  • マルチモーダル入力: テキスト+画像の混合入力をサポート、コードサンプルのvisionおよびmulti_imageの例を参照
<Note> **BaseURL**:デフォルトの BaseURL は `https://api.starmagic.ai` で、テキストモデルへの対応が優れており、長時間接続をサポートします。`https://api.starmagic.ai` はマルチモーダルの主力エンドポイントで、テキストモデルに対しては代替アドレスとして使用されます。 </Note>

認証

Authorizationstringheader必須

##すべてのAPIにBearer Token認証が必要です## **APIキーの取得:** [APIキー管理ページ](https://starmagic.ai/app/api-keys)にアクセスしてAPIキーを取得してください **リクエストヘッダーに追加:** ``` Authorization: Bearer YOUR_API_KEY ```

Authorization: Bearer YOUR_API_KEY

リクエストボディ

application/json
modelenum<gemini-2.5-flash>必須

チャットモデル名

"gemini-2.5-flash"
messagesobject[]必須

チャットメッセージのリスト、マルチターン対話とマルチモーダル入力をサポート

[
  {
    "role": "user",
    "content": null,
    "tool_call_id": "string"
  }
]
streamboolean

ストリーミングモードでレスポンスを返すかどうか - `true`: ストリーミング返却、リアルタイムでチャンク単位にコンテンツを受信 - `false`: 完全なレスポンスを一括で返却

false
max_completion_tokensinteger

Maximum number of completion tokens for the generated response, corresponding to Gemini's maxOutputTokens.

2000
max_tokensinteger

Maximum number of tokens for the generated response, compatible with the legacy OpenAI parameter.

2000
temperaturenumber

サンプリング温度、出力のランダム性を制御 **説明**: - 低い値(例: 0.2): より決定論的で集中した出力 - 高い値(例: 1.5): よりランダムで創造的な出力

0.7
top_pnumber

Nucleus Samplingパラメータ **説明**: - 累積確率に基づくトークンサンプリングを制御 - 例えば、0.9は累積確率90%までのトークンから選択することを意味します - デフォルト: 1.0(全トークンを考慮) **推奨**: temperatureとtop_pを同時に調整しないでください

0.9
frequency_penaltynumber

Frequency penalty coefficient. Range: -2.0 to 2.0. Corresponds to Gemini's frequencyPenalty.

0
presence_penaltynumber

Presence penalty coefficient. Range: -2.0 to 2.0. Corresponds to Gemini's presencePenalty.

0
stopobject

Stop sequences. Supports a string or string array, corresponding to Gemini's stopSequences.

ninteger

Number of generated candidates.

1
reasoning_effortenum<none | low | medium | high>

推論の負荷を制御します。Gemini 2.5 Flash と Flash Lite は none で思考を無効化でき、low/medium/high は異なる思考予算に対応します。

"medium"
seedinteger

Random seed used to make output as reproducible as possible, corresponding to Gemini's seed.

12345
logprobsboolean

Whether to return token logprob information, corresponding to Gemini's responseLogprobs.

true
top_logprobsinteger

Number of top logprob values returned for each token, corresponding to Gemini's logprobs.

5
response_formatobject

Response format settings, supporting JSON mode and JSON Schema, corresponding to Gemini's responseMimeType, responseSchema and responseJsonSchema.

stream_optionsobject

Streaming response options. Can be set when stream is true.

{
  "include_usage": true
}
toolsobject[]

List of tool definitions for Function Calling.

[
  {
    "type": "function",
    "function": {
      "name": "string",
      "description": "string",
      "parameters": {}
    }
  }
]
tool_choiceobject

Controls tool-calling behavior.

extra_bodyobject

Gemini extension parameters.

{
  "google": {
    "cached_content": "string",
    "thinking_config": {}
  }
}

レスポンス

application/json
成功

レスポンスボディ

idstring

チャット補完の一意の識別子

"chatcmpl-20251010015944503180122WJNB8Eid"
modelstring

実際に使用されたモデル名

"gemini-2.5-flash"
objectenum<chat.completion>

レスポンスタイプ

"chat.completion"
createdinteger

作成タイムスタンプ

1760032810
choicesobject[]

チャット補完選択肢のリスト

[
  {
    "index": 0,
    "message": {
      "role": "assistant",
      "content": "Hello! I'm pleased to introduce myself.\n\nI'm a Large Language Model, trained and developed by Google.\n\nSimply put, you can think of me as a \"smart brain\" that has been trained on massive amounts of text data and is able to understand and generate human language. My core capability is processing and generating text. Specifically, I can do the following:\n\n**1. Information Query & Knowledge Answering**\nI can act like a \"talking encyclopedia,\" answering various questions, whether they're about scientific knowledge, historical events, or everyday facts.\n\n**2. Creative Writing & Text Generation**\nI can create various types of text based on your requirements, such as:\n*   **Writing**: Poetry, stories, scripts, emails, speeches, advertising copy, etc.\n*   **Planning**: Travel plans, study outlines, event proposals, etc.\n*   **Brainstorming**: Working with you to generate new ideas and spark creativity.\n\n**3. Translation & Language Processing**\nI'm proficient in multiple languages and can provide fast, fluent translation services. I can also help you polish, proofread, summarize, or rewrite text to make your expression clearer and more professional.\n\n**4. Programming & Code Assistance**\nI can write code snippets, explain code logic, debug errors, or \"translate\" code from one programming language to another, making me a helpful companion for programmers.\n\n**5. Logical Analysis & Reasoning**\nI can help you analyze complex problems, organize logical chains, and make inferences and summaries based on the information you provide.\n\n---\n\n**In summary**, my goal is to be a powerful and useful tool that helps you obtain information more efficiently, complete tasks, and spark creativity through natural language communication.\n\n**Remember:** I'm an artificial intelligence, my knowledge comes from the data I've learned, and it may not be the most up-to-date. Sometimes I may also make mistakes, so for very important information, I recommend you verify it again.",
      "tool_calls": [
        null
      ]
    },
    "logprobs": {
      "content": [
        {
          "token": null,
          "logprob": null,
          "bytes": null,
          "top_logprobs": null
        }
      ]
    },
    "finish_reason": "stop"
  }
]
usageobject

トークン使用統計

{
  "prompt_tokens": 13,
  "completion_tokens": 1891,
  "total_tokens": 1904,
  "prompt_tokens_details": {
    "cached_tokens": 0,
    "text_tokens": 13,
    "audio_tokens": 0,
    "image_tokens": 0
  },
  "completion_tokens_details": {
    "text_tokens": 0,
    "audio_tokens": 0,
    "reasoning_tokens": 1480
  },
  "input_tokens": 0,
  "output_tokens": 0,
  "input_tokens_details": null
}
POST/v1/chat/completions
curl --request POST \
  --url https://api.starmagic.ai/v1/chat/completions \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "gemini-2.5-flash",
  "messages": [
    {
      "role": "user",
      "content": "Please introduce yourself"
    }
  ]
}'
レスポンス: 成功
{
  "id": "chatcmpl-20251010015944503180122WJNB8Eid",
  "model": "gemini-2.5-flash",
  "object": "chat.completion",
  "created": 1760032810,
  "choices": [
    {
      "index": 0,
      "message": {
        "role": null,
        "content": null,
        "tool_calls": null
      },
      "logprobs": {
        "content": [
          null
        ]
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 13,
    "completion_tokens": 1891,
    "total_tokens": 1904,
    "prompt_tokens_details": {
      "cached_tokens": 0,
      "text_tokens": 13,
      "audio_tokens": 0,
      "image_tokens": 0
    },
    "completion_tokens_details": {
      "text_tokens": 0,
      "audio_tokens": 0,
      "reasoning_tokens": 1480
    },
    "input_tokens": 0,
    "output_tokens": 0,
    "input_tokens_details": null
  }
}