Tokenthon provides a compatibility layer that enables you to use the standard OpenAI SDK to access our powerful AI models. With minimal code changes, you can quickly integrate Tokenthon's cost-effective AI capabilities into your existing applications.



To use the OpenAI SDK compatibility feature, you'll need to:

  1. Use an official OpenAI SDK (or any compatible HTTP client)
  2. Update your base URL to point to Tokenthon's API
  3. Replace your API key with a Tokenthon API key
  4. Use Tokenthon model names (e.g., gpt-auto, gpt-5-mini, gpt-5, gpt-5.2)
  5. Review the documentation below for what features are supported

python
from openai import OpenAI
 
client = OpenAI(
    api_key="YOUR_TOKENTHON_API_KEY",
    base_url="https://api.tokenthon.com/v1/"
)
 
response = client.chat.completions.create(
    model="gpt-auto", # Tokenthon auto-selects the best model
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Who are you?"}
    ],
)
 
print(response.choices[0].message.content)

Tokenthon supports the following model names through the OpenAI compatibility layer:

Model NameDescriptionTier
gpt-autoAutomatically selects the best available modelFree & Premium
gpt-5-miniLightweight, fast model for simple tasksFree & Premium
gpt-5Premium model for complex tasksPremium
gpt-5.2Advanced model with enhanced capabilitiesPremium

Here are the most substantial differences from using the standard OpenAI API:

  • Streaming is not supported - The stream parameter is accepted but not implemented. All responses are returned as complete messages.
  • Tool calling is not supported - Tool messages (role: "tool") and function calling are filtered out and not processed.
  • Most parameters are ignored - Parameters like temperature, top_p, stop, presence_penalty, frequency_penalty, and others are accepted by the schema but not used in the actual processing.
  • Response format validation - JSON schema validation is performed by the model but not strictly enforced by Tokenthon.
  • Multiple choices not supported - The n parameter must be exactly 1.

Most unsupported fields are silently ignored rather than producing errors. These are all documented below.

If you've done lots of tweaking to your prompt, it's likely to be well-tuned to OpenAI specifically. You may need to adjust your prompts slightly when migrating to Tokenthon, especially if you rely on features that are not supported in our compatibility layer.

Tokenthon's compatibility layer supports both system and developer roles. However, our internal API uses a slightly different role system:

  • OpenAI system messages are mapped to Tokenthon's developer role
  • OpenAI developer messages are mapped to Tokenthon's developer role
  • user and assistant roles remain unchanged

This mapping is handled automatically, so you don't need to change your message structure.


Rate limits follow Tokenthon's standard limits for the /v1/chat/completions endpoint. Please refer to your account dashboard or contact support for specific rate limit details.


FieldSupport StatusNotes
modelFully supportedUse Tokenthon model names (gpt-auto, gpt-5-mini, gpt-5, gpt-5.2)
max_tokensAcceptedValidated but not passed to underlying model
max_completion_tokensAcceptedValidated but not passed to underlying model
streamAcceptedNot implemented - always returns complete response
stream_optionsAcceptedIgnored
top_pAcceptedIgnored - only affects sampling in original OpenAI API
parallel_tool_callsAcceptedIgnored - tool calling not supported
stopAcceptedIgnored
temperatureAcceptedIgnored - must be between 0 and 2
nAcceptedMust be exactly 1 - multiple choices not supported
logprobsAcceptedIgnored
metadataAcceptedIgnored
response_formatFully supportedSupports text, json_object, and json_schema
predictionAcceptedIgnored
presence_penaltyAcceptedIgnored
frequency_penaltyAcceptedIgnored
seedAcceptedIgnored
service_tierAcceptedIgnored
audioAcceptedIgnored - audio input not supported
logit_biasAcceptedIgnored
storeAcceptedIgnored
userAcceptedIgnored
modalitiesAcceptedIgnored
top_logprobsAcceptedIgnored
reasoning_effortAcceptedIgnored

Tools (tools[n].function fields)

FieldSupport Status
nameAccepted but ignored
descriptionAccepted but ignored
parametersAccepted but ignored
strictAccepted but ignored

Functions (functions[n] fields)

OpenAI has deprecated the functions field and suggests using tools instead.

FieldSupport Status
nameAccepted but ignored
descriptionAccepted but ignored
parametersAccepted but ignored
strictAccepted but ignored

Developer Role

Fields for messages[n].role == "developer"

FieldSupport StatusNotes
contentFully supportedMapped to Tokenthon's developer role
nameAcceptedIgnored

System Role

Fields for messages[n].role == "system"

FieldSupport StatusNotes
contentFully supportedMapped to Tokenthon's developer role
nameAcceptedIgnored

User Role

Fields for messages[n].role == "user"

FieldVariantSub-fieldSupport Status
contentstringFully supported
array, type == "text"Fully supported
array, type == "image_url"urlFully supported
detailAccepted but ignored
array, type == "input_audio"Ignored - audio not supported
array, type == "file"Ignored
nameAccepted but ignored

Assistant Role

Fields for messages[n].role == "assistant"

FieldVariantSupport Status
contentstringFully supported
array, type == "text"Fully supported
array, type == "refusal"Accepted but ignored
tool_callsAccepted but ignored - tool calling not supported
function_callAccepted but ignored - function calling not supported
audioIgnored - audio not supported
refusalIgnored

Tool Role

Fields for messages[n].role == "tool"

FieldVariantSupport Status
contentstringFiltered out - tool messages not supported
array, type == "text"Filtered out - tool messages not supported
tool_call_idFiltered out - tool messages not supported
tool_choiceFiltered out - tool messages not supported
nameFiltered out - tool messages not supported

Function Role

Fields for messages[n].role == "function"

FieldVariantSupport Status
contentstringFiltered out - function messages not supported
array, type == "text"Filtered out - function messages not supported
tool_choiceFiltered out - function messages not supported
nameFiltered out - function messages not supported

FieldSupport StatusNotes
idFully supportedFormat: chatcmpl-{jobId}
choices[]Fully supportedAlways has a length of 1
choices[].finish_reasonFully supportedValues: stop, length, content_filter
choices[].indexFully supportedAlways 0
choices[].message.roleFully supportedAlways assistant
choices[].message.contentFully supportedThe assistant's response
choices[].message.tool_callsAlways emptyTool calling not supported
choices[].message.refusalAlways emptyNot supported
choices[].message.audioAlways emptyAudio not supported
objectFully supportedAlways chat.completion
createdFully supportedUnix timestamp
modelFully supportedThe requested model name
finish_reasonFully supportedSame as choices[].finish_reason
contentFully supportedSame as choices[].message.content
usage.completion_tokensFully supportedEstimated token count
usage.prompt_tokensFully supportedEstimated token count
usage.total_tokensFully supportedSum of prompt and completion tokens
usage.completion_tokens_detailsAlways emptyNot supported
usage.prompt_tokens_detailsAlways emptyNot supported
logprobsAlways emptyNot supported
service_tierAlways emptyNot supported
system_fingerprintAlways emptyNot supported

The compatibility layer maintains consistent error formats with the OpenAI API. Error responses include:

typescript
{
    "error": {
        "message": "Error description here",
        "type": "error_type",
        "param": undefined,
        "code": "status_code_string"
    }
}

Error types are mapped based on HTTP status codes:

Status CodeError Type
400invalid_request_error
401invalid_request_error
403permission_error
404not_found_error
408timeout_error
429rate_limit_error
500api_error
502api_error
503service_unavailable_error
504timeout_error

The detailed error messages will not be equivalent to OpenAI's. We recommend only using the error messages for logging and debugging.

While the OpenAI SDK automatically manages headers, here is the complete list of headers supported by the Tokenthon API for developers who need to work with them directly.

HeaderSupport StatusNotes
authorizationFully supportedBearer token authentication
content-typeFully supportedMust be application/json
x-request-idSupportedRequest tracking identifier

Note: Tokenthon does not return rate limit headers in the current implementation. Please monitor your usage through the dashboard.


python
response = client.chat.completions.create(
    model="gpt-5",
    messages=[
        {"role": "system", "content": "You are a helpful assistant that responds in JSON."},
        {"role": "user", "content": "Extract the name and age from this text: John is 25 years old."}
    ],
    response_format={"type": "json_object"}
)
 
print(response.choices[0].message.content)

python
response = client.chat.completions.create(
    model="gpt-5",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Extract structured data from this text: The meeting is on January 15, 2024 at 3 PM."}
    ],
    response_format={
        "type": "json_schema",
        "json_schema": {
            "name": "event_extraction",
            "schema": {
                "type": "object",
                "properties": {
                    "date": {"type": "string"},
                    "time": {"type": "string"}
                },
                "required": ["date", "time"]
            }
        }
    }
)
 
print(response.choices[0].message.content)

python
response = client.chat.completions.create(
    model="gpt-auto",
    messages=[
        {"role": "system", "content": "You are a helpful customer service agent."},
        {"role": "user", "content": "I have a question about my order."},
        {"role": "assistant", "content": "I'd be happy to help! What's your order number?"},
        {"role": "user", "content": "Order #12345"}
    ]
)
 
print(response.choices[0].message.content)