From OpenAI#
Keep your OpenAI client and change base_url to https://weightsapi.com/v1, api_key to your WeightsAPI key, and model to a connected open-model ID. If your previous model name was OpenAI-specific, changing the model is also required.
The compatibility scope is Chat Completions, Completions, Embeddings and Models. Responses, Assistants and provider-specific tools are not drop-in compatible.
From Anthropic#
Install the OpenAI client. Replace anthropic.Anthropic with OpenAI, messages.create with chat.completions.create, and response.content[0].text with response.choices[0].message.content. Move the top-level system prompt to the first messages entry with role: system. Keep max_tokens, and translate tool schemas from input_schema to function.parameters.
Anthropic migration is an SDK and message-format change. It is not just a URL swap.
Verify before switching traffic#
Run a small representative dataset; check tool calls, JSON validation, context limits and output quality. Compare costs using actual token counts. Keep a rollback path.
OpenAI: exact Python changes#
-client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
+client = OpenAI(base_url="https://weightsapi.com/v1", api_key=os.environ["WEIGHTSAPI_API_KEY"])
-response = client.chat.completions.create(model="gpt-5.4", messages=messages)
+response = client.chat.completions.create(model="Qwen/Qwen3-32B", messages=messages)
-from anthropic import Anthropic
-client = Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])
-response = client.messages.create(model="claude-sonnet-5", system="Be concise.", max_tokens=256, messages=messages)
-print(response.content[0].text)
+from openai import OpenAI
+client = OpenAI(base_url="https://weightsapi.com/v1", api_key=os.environ["WEIGHTSAPI_API_KEY"])
+response = client.chat.completions.create(model="Qwen/Qwen3-32B", max_tokens=256, messages=[{"role":"system","content":"Be concise."}, *messages])
+print(response.choices[0].message.content)
Request example
curl https://weightsapi.com/v1/chat/completions \
-H "Authorization: Bearer $WEIGHTSAPI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "Qwen/Qwen3-32B",
"messages": [
{
"role": "user",
"content": "Hello!"
}
],
"stream": true
}'