Integration guide

Drop in 1chat without rewriting your SDK code

Create a prepaid balance, generate an API key in the portal, then change the base URL and model name in your existing provider SDK.

Base URLs

OpenAI Chat, Completions, Responseshttps://api.1chat.co/v1
Anthropic Messageshttps://api.1chat.co/anthropic
Gemini GenerateContenthttps://api.1chat.co/gemini/v1beta
Authentication

Send `Authorization: Bearer sk_1chat_...` or `x-api-key: sk_1chat_...`. Gemini-compatible requests may also pass `?key=sk_1chat_...` for SDKs that expect key-based auth.

OpenAI Chat Completions

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.ONECHAT_API_KEY,
  baseURL: "https://api.1chat.co/v1"
});

const completion = await client.chat.completions.create({
  model: "1chat/auto",
  messages: [
    { role: "system", content: "You are a careful tax assistant." },
    { role: "user", content: "Can I deduct a home office if I am a W-2 employee?" }
  ],
  metadata: {
    conversation_id: "tax-session-42",
    user_id: "customer_123"
  }
});

OpenAI Responses

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.ONECHAT_API_KEY,
  baseURL: "https://api.1chat.co/v1"
});

const response = await client.responses.create({
  model: "1chat/auto",
  input: [
    {
      role: "user",
      content: "Extract filing status, dependents, and likely missing documents from this intake note."
    }
  ],
  metadata: {
    conversation_id: "intake-887"
  }
});

Anthropic Messages

The official Anthropic SDK appends `/v1/messages` to the base URL. Use the bare 1chat Anthropic base URL below.

import Anthropic from "@anthropic-ai/sdk";

const anthropic = new Anthropic({
  apiKey: process.env.ONECHAT_API_KEY,
  baseURL: "https://api.1chat.co/anthropic"
});

const message = await anthropic.messages.create({
  model: "1chat/auto",
  max_tokens: 600,
  messages: [
    { role: "user", content: "Explain the tradeoff between standard and itemized deductions." }
  ]
});

Gemini GenerateContent

Gemini SDKs often put the model in the URL. 1chat accepts API-key auth as a bearer token, `x-api-key`, or Gemini-style `key` query parameter.

curl "https://api.1chat.co/gemini/v1beta/models/1chat-auto:generateContent?key=$ONECHAT_API_KEY" \
  -H "content-type: application/json" \
  -H "x-1chat-conversation-id: tax-session-42" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [{ "text": "Summarize estimated tax payment deadlines." }]
      }
    ]
  }'

Trace and conversation headers

1chat can infer a conversation from metadata, but explicit IDs produce cleaner trace assembly across provider surfaces and framework boundaries.

`x-1chat-conversation-id`Groups calls into a multi-turn conversation trace.
`x-1chat-trace-id`Connects 1chat with upstream distributed tracing.
`traceparent`Accepted when you already use W3C trace context.

Model names

`1chat/auto`

Let 1chat choose according to your project policy, eval evidence, and aggressiveness setting.

`1chat/balanced`

Bias toward quality-preserving savings when the project has enough labels and shadow results.

`1chat/cost-saver`

Use a more aggressive cost posture while retaining explicit project quality floors.

Provider IDs

Pin a provider model such as `openai/gpt-4.1` or `gemini/gemini-2.5-flash-lite` when exactness matters.

Error contract

{
  "error": {
    "type": "insufficient_prepaid_balance",
    "message": "Insufficient prepaid balance.",
    "balance_usd": 0,
    "reserved_usd": 0,
    "required_usd": 0.0121
  }
}

A `402` means 1chat did not send the provider request. Add balance or enable auto recharge, then retry the request with the same application-level idempotency strategy you use today.