• English
  • Advanced API Usage

    Once the basics work, this page covers what production use actually needs: streaming, common parameters, vision input, SDKs, and retry strategy. Replace MODEL_ID in the examples with a real ID copied from the model plaza; minimal request examples live in API Endpoints.

    Streaming

    Conversational apps almost always want streaming (typewriter effect). Add "stream": true to the request body and the response arrives chunk by chunk over SSE (Server-Sent Events):

    curl https://tokens.byteseek.ai/v1/chat/completions \
      -H "Authorization: Bearer sk-your-key" \
      -H "Content-Type: application/json" \
      -d '{
        "model": "MODEL_ID",
        "stream": true,
        "messages": [{ "role": "user", "content": "Write a short poem about the sea" }]
      }'

    Notes:

    • Each chunk starts with data: ; the stream ends with data: [DONE];
    • SDKs handle chunking for you (see below); if parsing yourself, split by line and skip blanks;
    • With reasoning models, time-to-first-token stays long even with streaming — the thinking phase produces no visible output, so set generous client timeouts;
    • The Anthropic format supports "stream": true too, with a different event structure — use the Anthropic SDK.

    Common parameters

    Parameters follow the upstream vendor's docs for each protocol; the most used ones:

    ParameterEffectSuggestion
    temperatureRandomness; lower is steadier0–0.3 for code / extraction, 0.7–1 for creative writing
    max_tokens / max_output_tokensCaps output lengthSet it to avoid surprise long outputs inflating cost
    streamStreaming outputRecommended for conversational apps
    reasoning_effortReasoning strength (thinking models)low / medium / high; higher is slower and pricier — usage logs record it per call
    response_formatStructured outputUse json_object or json_schema when you need machine-parseable results
    Parameters pass through

    The gateway forwards request bodies as-is per protocol. Anything the upstream model supports works without gateway-side configuration; unsupported parameters are rejected by the upstream.

    Vision input (images)

    Vision-capable models accept images in messages. OpenAI Chat format:

    curl https://tokens.byteseek.ai/v1/chat/completions \
      -H "Authorization: Bearer sk-your-key" \
      -H "Content-Type: application/json" \
      -d '{
        "model": "MODEL_ID",
        "messages": [{
          "role": "user",
          "content": [
            { "type": "text", "text": "Describe this image" },
            { "type": "image_url", "image_url": { "url": "https://example.com/photo.jpg" } }
          ]
        }]
      }'
    • Images can be public URLs or inline data:image/jpeg;base64,... data;
    • Images count as input tokens — large images cost noticeably more, compress first;
    • Whether a model supports vision follows the capability labels in the model plaza.

    SDKs

    Official SDKs only need base_url and api_key changed:

    Python (OpenAI)
    Node.js (OpenAI)
    Python (Anthropic)
    from openai import OpenAI
    
    client = OpenAI(
        base_url="https://tokens.byteseek.ai/v1",
        api_key="sk-your-key",
    )
    
    stream = client.chat.completions.create(
        model="MODEL_ID",
        messages=[{"role": "user", "content": "Hello"}],
        stream=True,
    )
    for chunk in stream:
        delta = chunk.choices[0].delta.content
        if delta:
            print(delta, end="", flush=True)

    Keep keys in environment variables (OPENAI_API_KEY / ANTHROPIC_API_KEY) — SDKs read them automatically. Never hard-code keys into committed code; see the security requirements in the Acceptable Use Policy.

    Timeouts and retries

    For production robustness:

    • Generous timeouts: reasoning models respond on the scale of minutes; set client timeouts ≥ 300 s;
    • Exponential backoff: retry 429 and 5xx with 1s → 2s → 4s intervals, 3–5 attempts max; other 4xx errors are request problems where retrying is pointless;
    • Don't blast concurrency: dense retries without backoff get automatically deprioritised, see Rate Limits & Concurrency;
    • Log request IDs: the request ID in response headers is the one handle for debugging and support tickets.
    © 2026 ByteSeek Limited. All rights reserved.TermsPrivacyDisclaimer