Native SDK'lar

OpenAI SDK

TokenLab'i resmi OpenAI SDK'leri ve OpenAI uyumlu istemcilerle kullanın

Genel Bakış

Bir OpenAI SDK istemcisini https://api.tokenlab.sh/v1 adresine yönlendirin ve bir TokenLab API anahtarı kullanın. Uygulamanızın halihazırda kullandığı API metodunu koruyun ve seçilen modelin bunu accepted_request_formats aracılığıyla desteklediğini doğrulayın.

Python, JavaScript ve Go resmi OpenAI SDK'lerine sahiptir. PHP, OpenAI uyumlu topluluk istemcileriyle iyi çalışır, ancak resmi bir OpenAI SDK'si değildir.

Kurulum

pip install openai

Responses girdi öğeleri, araçlar veya devam ettirme işlemleri için POST /v1/responses kullanın. İsteğe bağlı alanlar seçilen modele bağlıdır.

İstemciyi Yapılandırma

from openai import OpenAI

client = OpenAI(
    api_key="sk-your-tokenlab-key",
    base_url="https://api.tokenlab.sh/v1",
)

Önerilen: Chat Completions

response = client.chat.completions.create(
    model="gpt-5.6-terra",
    messages=[{"role": "user", "content": "Reply with: Connected to TokenLab."}]
)

print(response.choices[0].message.content)

Gelişmiş: Responses API

Bu yolu yalnızca aracınız veya iş akışınız açıkça OpenAI Responses semantiğine bağlı olduğunda kullanın.

Responses ile Akış (Streaming)

stream = client.responses.create(
    model="gpt-5.6-terra",
    input="Write a short poem about coding.",
    stream=True,
)

for event in stream:
    if event.type == "response.output_text.delta":
        print(event.delta, end="")

Araçlar / Fonksiyon Çağırma (Tools / Function Calling)

response = client.responses.create(
    model="gpt-5.6-terra",
    input="What's the weather in Tokyo?",
    tools=[{
        "type": "function",
        "name": "get_weather",
        "description": "Get weather for a location",
        "parameters": {
            "type": "object",
            "properties": {
                "location": {"type": "string"}
            },
            "required": ["location"]
        }
    }]
)

for item in response.output:
    if item.type == "function_call":
        print(item.name)
        print(item.arguments)

Responses ile Görsel İşleme (Vision)

response = client.responses.create(
    model="gpt-5.6-terra",
    input=[{
        "role": "user",
        "content": [
            {"type": "input_text", "text": "What's in this image?"},
            {"type": "input_image", "image_url": "https://example.com/image.jpg"}
        ]
    }]
)

print(response.output_text)

Embeddings

response = client.embeddings.create(
    model="text-embedding-3-small",
    input="Hello world"
)

print(response.data[0].embedding[:5])

Sorun Giderme

Bu sayfada