API REFERENCE

Chat Completions

Generate responses from text messages and supported inline images or PDFs.

POST /v1/chat/completions

Send a model ID and an array of messages. Supported roles are system, developer, user, assistant and tool; role support also depends on the model. Message content can be a text string or an array of supported content parts. Compatible models accept inline base64 images and PDFs in user messages. An assistant function call may use null content.

curl https://api.tokely.me/v1/chat/completions \
  -H "Authorization: Bearer $TOKELY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.4-mini",
    "messages": [{"role": "user", "content": "Hello, Tokely!"}],
    "max_tokens": 1024
  }'

Core parameters

Optional generation settings must be supported by the selected model.

ParameterDescription
modelRequired. Exact enabled model ID.
messagesRequired. Between 1 and 128 messages; supported content depends on the model.
max_tokens / max_completion_tokensOutput budget. Use one, never both. Default: 256.
streamSet true for SSE. Default: false.
temperature / top_pSampling settings, when supported.
tools / tool_choiceUp to 32 function tools; model support required.
response_formattext, json_object or json_schema; model support required.
nOnly 1 is supported.

Continue a conversation

Send the prior messages along with the new user message. The following example makes two requests and includes the first answer in the second request.

Each request includes and bills its submitted input history. Trim old turns when the conversation approaches the model context limit. For assistant tool calls, preserve the tool_calls fields and corresponding tool results as described in Function calling.

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["TOKELY_API_KEY"],
    base_url="https://api.tokely.me/v1",
)
messages = [
    {"role": "system", "content": "Answer briefly."},
    {"role": "user", "content": "What is an API?"},
]
first = client.chat.completions.create(
    model="gpt-5.4-mini", messages=messages, max_tokens=1024,
)
print(first.choices[0].message.content)
messages.append({
    "role": "assistant", "content": first.choices[0].message.content,
})
messages.append({"role": "user", "content": "Give me an example."})
second = client.chat.completions.create(
    model="gpt-5.4-mini", messages=messages, max_tokens=1024,
)
print(second.choices[0].message.content)

Read the response

Read choices[0].message.content for text, choices[0].message.tool_calls for function calls, and usage for token counts. A finish reason of length indicates that the output budget was reached.

Carry conversation history forward in messages on the next request. Tokely does not automatically retain your conversation.

EXPLORE DOCUMENTATION

IntroductionConnect your app to AI models through one familiar API. This is your guide to building with Tokely.QuickstartMake your first Tokely request in three steps.API keysConnect securely with a key from your Tokely dashboard.ModelsChoose an available model and use its exact ID in your request.PlaygroundUse the Tokely Playground to test prompts before writing code.Use your existing appConnect an existing OpenAI-compatible application to Tokely.Chat CompletionsGenerate responses from text messages and supported inline images or PDFs.ResponsesUse stateless text and supported multimodal input with the Responses API.EmbeddingsTurn text into vectors for search, RAG, clustering and classification with the OpenAI-compatible /v1/embeddings endpoint.Claude Code and the Messages APIPoint Claude Code or the Anthropic SDK at Tokely. Use the native /v1/messages endpoint with streaming, tools and prompt caching.Images and PDFsSend inline images and PDFs to compatible models through Chat Completions or Responses.Images, video & audioGenerate media with your Tokely API key and account balance.Errors & limitsDiagnose failed requests and keep your integration within service limits.StreamingDisplay generated text as it arrives with server-sent events.Function callingLet a model request a function, then execute it in your application.Structured outputRequest JSON output or a defined schema from a compatible model.Usage & billingModel prices, account balance and output reservations.WebhooksTokely webhook events, HMAC signature verification, delivery retries and replay behavior.
Use Tab to browse results ESC to close