Claude code api Documentation: Quick Start
Start using the uncensored coding AI immediately with this openai compatible API. We provide the endpoint URL, authentication details, and code examples to help you integrate the claude code API into your workflow.
Endpoint URL and Authentication
The base URL for all requests is https://api.claudecodeapi.com/v1. You authenticate by passing your API key in the Authorization header. Use the format Bearer YOUR_API_KEY for every request. This setup works with any standard OpenAI-compatible client.
You get a key instantly after signing up. No phone number is required. The key is shown immediately on the dashboard. You can replace it with a new one if needed. Errors and refusals do not charge your credit. This ensures you only pay for actual output.
Sending your first request with Python
Use the official OpenAI Python SDK to send requests. Set the base URL to our endpoint. Use the model ID uncensored for the best results. This allows you to swap your existing code with minimal changes. You can process large batches of text efficiently.
The API supports standard parameters like temperature and top_p. These help you control the creativity of the output. Streaming is available for real-time token delivery. You can also use JSON mode for structured data.
Streaming responses and token usage
Enable streaming by setting stream=True in your request. The server sends tokens as they are generated. You receive the final token usage in the last chunk. This helps you track costs in real time. You do not need to wait for the full response.
Streaming works with all model parameters. You can adjust top_p for diversity. Use seed for reproducibility. The API supports function calling too. You can define tools for specific tasks. JSON mode ensures strict output formats.
Function calling and JSON mode
Define tools in your request to enable function calling. The model returns structured data that you can execute. Use response_format set to json_object for strict JSON. This ensures consistent parsing in your code. You can pass complex schemas for validation.
Function calling works with streaming responses. You receive the tool calls as they are generated. This allows for interactive workflows. You can combine JSON mode with function calling. Use tool_choice to control the behavior. This gives you full control over the output.
Rate limits and error handling
You are limited to 300 requests per minute per key. You can have 8 concurrent requests at the same time. The request body must be under 8 MB. If you exceed the limit, you receive a 429 error. Handle this by implementing a retry with backoff.
A 401 error means your key is invalid. A 402 error indicates no credit. Check your account balance. Errors and refusals are free. This means you do not pay for failed requests. Use the Support page for refunds if needed.
Context window and max tokens
The context window is 100,000 tokens. This includes both prompt and completion. You can send large documents efficiently. There is no separate output cap: a response can use all the room left in the window. If you do not set max_tokens, the response can run to the end of the window. The 100,000-token window is shared by prompt and completion.
This large window supports complex coding tasks. You can include full codebases in the prompt. The model maintains context across long conversations. Use stop sequences to control output. This helps in generating specific formats. You can also use presence_penalty and frequency_penalty for variety.
cURL
curl https://api.claudecodeapi.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "Show me the usage stats for last week."}]
}'Python
from openai import OpenAI
client = OpenAI(base_url="https://api.claudecodeapi.com/v1", api_key="YOUR_KEY")
resp = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Summarise this thread without softening it."}],
)
print(resp.choices[0].message.content)Node.js
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.claudecodeapi.com/v1", apiKey: process.env.API_KEY });
const resp = await client.chat.completions.create({
model: "uncensored",
messages: [{ role: "user", content: "Draft a villain monologue for my game." }],
});
console.log(resp.choices[0].message.content);Streaming
stream = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Tell the story in second person."}],
stream=True,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)Support queries
How does the claude code API work?
It is an OpenAI-compatible API that serves an uncensored model. You send requests to our endpoint and receive text responses. The billing is prepaid and based on token usage. Errors and refusals do not charge your credit.
What is the context window size?
The context window is 100,000 tokens for both input and output. You can send large prompts without losing context. The maximum output per request is up to the full 100,000-token window. This supports complex coding and data processing tasks.
Can I use the official OpenAI SDK?
Yes, you can use any OpenAI-compatible SDK. Set the base URL to our endpoint. Use the model ID <code>uncensored</code>. The API supports streaming, function calling, and JSON mode. This allows for easy integration with your existing code.
Access key via sign-up
Register, copy the token, update the base URL. That covers the entire configuration.