Flat-rate APIs for your agents.

Use your coding model through OpenAI-compatible Chat Completions or Responses. Paid plans use monthly pricing, not per-token billing. Requests share capacity and may queue.

Make your first call

  1. List published modelsExport your key on the server. Choose a listed model included in your plan.
  2. Select a model and send a promptUse a live, non-deprecated ID. If the list includes a Qwen compatibility alias, choose glm-5.3-flash instead.
$ export BHARATCODE_API_KEY=bc_live_your_key_here
$ curl -fsS https://bharatcode.ai/api/model/v1/models -H "Authorization: Bearer $BHARATCODE_API_KEY"
$ export BHARATCODE_MODEL='<listed model ID>'
$ curl https://bharatcode.ai/api/model/v1/responses -H "Authorization: Bearer $BHARATCODE_API_KEY" -H "Content-Type: application/json" -d '{"model":"'"$BHARATCODE_MODEL"'","input":"Say hello from BharatCode","store":false}'

Coding models by plan

The GLM-5.3 Flash switch is scheduled for 15 Nov 2026 at 18:30 UTC (00:00 on 16 Nov IST). From then until 00:00 on 23 Nov IST, the old Qwen ID sends requests to GLM on all API plans: verified student, Lite and Pro. Choose glm-5.3-flash once GET /models lists it as live. During the compatibility week, qwen-3.8-27b is an alias with the same inputs as GLM. Use images only if GLM lists image in metadata.input; video requires its own check and listing. From 00:00 on 23 Nov IST the old ID returns HTTP 410 (retired_model). Keep your existing API base URL and key.

List published model IDs
$ curl -fsS https://bharatcode.ai/api/model/v1/models -H "Authorization: Bearer $BHARATCODE_API_KEY"
ModelUse it forEndpointAccess
GLM-5.3 Flashglm-5.3-flash
Coding, reasoning and tool use · Image input/responses · /chat/completionsStudents (10M tokens a day), Lite and Pro
BharatCode DeepSeek V4.1 Flash (1017)deepseek-v4.1-flash
Coding, long-context reasoning and tool use · Image input/responses · /chat/completionsPro

Copy a working request

Examples use the BHARATCODE_MODEL and BHARATCODE_API_KEY you exported in the Bash quickstart.

POSTCreate a response/responses

Send input as text or a message array, with optional instructions. Use store:false. Read text and function calls from the output array.

$ curl https://bharatcode.ai/api/model/v1/responses -H "Authorization: Bearer $BHARATCODE_API_KEY" -H "Content-Type: application/json" -d '{"model":"'"$BHARATCODE_MODEL"'","input":"Say hello from BharatCode","store":false}'
POSTStream a response/responses

Set stream:true for server-sent events. Text arrives in response.output_text.delta; finish on response.completed or response.incomplete. An incomplete response with reason max_output_tokens reached its output budget, including reasoning. Preserve partial output; increase max_output_tokens or use reasoning:{effort:"none"} for short answers. Handle response.failed as an error. Include the x-request-id response header when reporting a problem. Queue keepalive comments are not model output.

$ curl -N https://bharatcode.ai/api/model/v1/responses -H "Authorization: Bearer $BHARATCODE_API_KEY" -H "Content-Type: application/json" -d '{"model":"'"$BHARATCODE_MODEL"'","input":"Explain a binary search in three steps","store":false,"stream":true}'
POSTCall your own tools/responses

Define function tools using name and parameters. Your application validates arguments and executes the function; BharatCode does not run it. For the next request, include the original input, the response.output items, and a function_call_output item with the matching call_id and a string output. Keep store:false and resend any tool definitions you still need.

$ curl https://bharatcode.ai/api/model/v1/responses -H "Authorization: Bearer $BHARATCODE_API_KEY" -H "Content-Type: application/json" -d '{"model":"'"$BHARATCODE_MODEL"'","input":"What is the weather in Delhi?","store":false,"tools":[{"type":"function","name":"get_weather","description":"Look up current weather for a city","parameters":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"],"additionalProperties":false},"strict":true}],"tool_choice":{"type":"function","name":"get_weather"}}'
POSTGenerate code and call tools/chat/completions

Send OpenAI-compatible messages to a published model included in your plan. The model field is required. A finish_reason of length means the output budget was exhausted, even with HTTP 200. Preserve partial output and do not execute incomplete tool calls. Increase max_tokens (within the model’s output limit, including reasoning) or use reasoning_effort:"none" for short answers. Retrying the same small budget may stop at the same limit.

$ curl https://bharatcode.ai/api/model/v1/chat/completions -H "Authorization: Bearer $BHARATCODE_API_KEY" -H "Content-Type: application/json" -d '{"model":"'"$BHARATCODE_MODEL"'","messages":[{"role":"user","content":"Say hello from BharatCode"}]}'

Use the OpenAI SDK

Use the model ID and server-side key from the quickstart.

import OpenAI from 'openai'

const client = new OpenAI({
  apiKey: process.env.BHARATCODE_API_KEY,
  baseURL: 'https://bharatcode.ai/api/model/v1',
})

const response = await client.responses.create({
  model: process.env.BHARATCODE_MODEL,
  input: 'Build a study planner schema',
  store: false,
})
console.log(response.output_text)

Responses support

  • Supported: text input, streaming, your own function tools, and structured output through text.format. Send the conversation history with each request.
  • Media: Check the live model’s metadata.input. If it lists image, use image_url in Chat Completions or input_image in Responses. Only if GLM also lists video, send one self-contained MP4 per request (up to 4 MiB and 30 seconds). Use a public HTTPS URL or an inline data:video/mp4;base64,… URL. In Chat Completions, put the URL in video_url.url on a video_url part. In Responses, set the video_url string on an input_video part. BharatCode fetches and validates public clips; the provider receives only inline data.
  • Not supported: store:true, previous_response_id, hosted tools, background jobs, and audio or file input. These return 400.

When it's busy

A 503 means the model is busy. Wait a few seconds and retry. A stream that has already started ends with response.failed instead.