Skip to main content
Create an API key and make your first call.

Call Tokensmind API directly

::: tip Replace <Tokensmind_API_KEY> with your Tokensmind key. Mind the key’s expiry and quota limits. ::: For available model values, see the model hub and copy the model name into your request. ::: code-group
[Python]
import requests
import json

response = requests.post(
    url="https://tokensmind.ai/v1/chat/completions",
    headers={
        "Authorization": "Bearer <Tokensmind_API_KEY>",
        "Content-Type": "application/json",
    },
    data=json.dumps({
        "model": "gpt-4o-mini",  # replace with your model id
        "messages": [
            {
                "role": "user",
                "content": "What is the meaning of life?"
            }
        ]
    })
)
[JavaScript]
// Try from https://tokensmind.ai; other origins may hit browser CORS limits
fetch("https://tokensmind.ai/v1/chat/completions", {
  method: "POST",
  headers: {
    Authorization: "Bearer <Tokensmind_API_KEY>",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "gpt-4o-mini",
    messages: [
      {
        role: "user",
        content: "What is the meaning of life?",
      },
    ],
  }),
});
[Curl]
curl 'https://tokensmind.ai/v1/chat/completions' \
  -H 'Authorization: Bearer <Tokensmind_API_KEY>' \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "gpt-4o-mini",
    "messages": [
      {
        "role": "user",
        "content": "What is the meaning of life?"
      }
    ]
  }'
::: Streaming: add "stream": true to the request body.

Use the OpenAI SDK

Replace <Tokensmind_API_KEY> with your Tokensmind key. For model names, use the model hub. ::: code-group
[Python]
from openai import OpenAI
import random

client = OpenAI(
    base_url="https://tokensmind.ai/v1",
    api_key="<Tokensmind_API_KEY>",
)

completion = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[
        {
            "role": "developer",
            "content": "Always reply in English"
        },
        {
            "role": "user",
            "content": "What is the meaning of life?"
        }
    ],
    temperature=0.8,
    max_tokens=1024,
    top_p=1,
    frequency_penalty=0,
    presence_penalty=0,
    seed=random.randint(1, 1000000000),
)

print(completion.choices[0].message.content)
[JavaScript]
import OpenAI from "openai";

const openai = new OpenAI({
  baseURL: "https://tokensmind.ai/v1",
  apiKey: "<Tokensmind_API_KEY>",
});

async function main() {
  const completion = await openai.chat.completions.create({
    model: "gpt-4o-mini",
    messages: [
      {
        role: "user",
        content: "What is the meaning of life?",
      },
    ],
  });

  console.log(completion.choices[0].message);
}

main();
::: For search-capable models, you can add:
  web_search_options={}, # search options
Models: gpt-4o-search-preview, gpt-4o-mini-search-preview. ::: info Search models may not support temperature and some other fine-grained parameters. :::