Docs/AI SDK

AI

AI Gateway

Last updated April 17, 2026

The secure, unified API layer for your AI requests across models, providers, and runtime policies.

The AI Gateway is Cencori's runtime control point. Your application sends AI traffic to Cencori once, and Cencori handles provider routing, security enforcement, observability, and cost tracking.

Available Endpoints

EndpointDescriptionProviders
/api/ai/chatChat completionsOpenAI, Anthropic, Google, xAI, Mistral, DeepSeek, Meta
/api/ai/embeddingsVector embeddingsOpenAI, Google, Cohere
/api/ai/images/generateImage generationOpenAI, Google
/api/ai/audio/transcriptionsSpeech-to-textOpenAI
/api/ai/audio/speechText-to-speechOpenAI
/api/ai/moderationContent moderationOpenAI
https://api.cencori.com/v1/chat/completionsOpenAI-compatible chat endpointOpenAI-compatible clients

SDK Usage

Codetext
import { Cencori } from 'cencori';
 
const cencori = new Cencori({
  apiKey: process.env.CENCORI_API_KEY,
});
 
const response = await cencori.ai.chat({
  model: 'gpt-4o',
  messages: [
    { role: 'system', content: 'You are a helpful assistant.' },
    { role: 'user', content: 'Hello!' },
  ],
  temperature: 0.7,
  maxTokens: 1000,
});
 
console.log(response.content);
console.log(response.usage); // { promptTokens, completionTokens, totalTokens }

Streaming

Codetext
const stream = cencori.ai.chatStream({
  model: 'claude-opus-4',
  messages: [{ role: 'user', content: 'Tell me a story' }],
});
 
for await (const chunk of stream) {
  process.stdout.write(chunk.delta);
}

Tool Calling

Codetext
const response = await cencori.ai.chat({
  model: 'gpt-4o',
  messages: [{ role: 'user', content: 'What is the weather in Tokyo?' }],
  tools: [
    {
      type: 'function',
      function: {
        name: 'get_weather',
        description: 'Get weather for a location',
        parameters: {
          type: 'object',
          properties: { location: { type: 'string' } },
          required: ['location'],
        },
      },
    },
  ],
});
 
console.log(response.toolCalls);

Direct API Usage

Native Cencori Endpoint

Codetext
curl -X POST https://cencori.com/api/ai/chat \
  -H "CENCORI_API_KEY: csk_..." \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [{"role": "user", "content": "Hello!"}],
    "stream": false
  }'

OpenAI-Compatible Endpoint

Codetext
curl -X POST https://api.cencori.com/v1/chat/completions \
  -H "Authorization: Bearer csk_..." \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'

Authentication

Every request requires a project API key:

  • Preferred for /api/ai/*: CENCORI_API_KEY: csk_...
  • Required for https://api.cencori.com/v1/*: Authorization: Bearer csk_...

Create and manage project keys in the dashboard.