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.
Step 1 · Get a key
Create an API key in the 9Coding console; keys start with sk-9c-. Sign up first if you do not have an account.
Step 2 · Change the endpoint
In your existing OpenAI client, replace the endpoint and key with the values below. Pick Python, Node.js, or curl; switch the model name to suit the task.
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 is the better choice for long tasks. For the native Anthropic SDK, use the dedicated variables in the Claude Code guide.Step 3 · Verify the connection
Run one of the examples above. Once it returns a reply to ping, open the 9Coding console's Logs page and confirm that the matching call shows its model, tokens, and charge. Both checks confirm that the endpoint and key are active.
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.