SDK · about 2 minutes

Migrate the OpenAI SDK in one line

9Coding implements the OpenAI interface specification, so existing code needs exactly two parameters changed: base_url and the key. After that, switching models is just a different string — Claude, GPT and Gemini all answer on the same call.

Python

main.py
from openai import OpenAI

client = OpenAI(
    base_url="https://api.9coding.com/v1",  # this line is the whole migration
    api_key="sk-9c-your-key"
)

resp = client.chat.completions.create(
    model="claude-fable-5",   # swap for gpt-5.6, gemini-3.5-flash, …
    messages=[{"role": "user", "content": "ping"}]
)
print(resp.choices[0].message.content)

Node.js

main.mjs
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.9coding.com/v1",  // this line is the whole migration
  apiKey: "sk-9c-your-key",
});

const resp = await client.chat.completions.create({
  model: "claude-fable-5",
  messages: [{ role: "user", content: "ping" }],
});
console.log(resp.choices[0].message.content);

curl

terminal
curl https://api.9coding.com/v1/chat/completions \
  -H "Authorization: Bearer sk-9c-your-key" \
  -H "Content-Type: application/json" \
  -d '{"model":"claude-fable-5","messages":[{"role":"user","content":"ping"}]}'
Streaming works unchanged: stream=True over SSE is fully supported, and it's the better choice for long tasks. If you use the native Anthropic SDK instead, point its base URL at https://api.9coding.com.

Troubleshooting

  • 401 — wrong or truncated key; it should start with sk-9c-.
  • Model names — identical to the official names. The available list is in the console.
  • Where to see usage — the Logs page in the console shows the model, tokens and charge for every call.