AshnaAI API

The AshnaAI HTTP API speaks three client protocols on one host: OpenAI Chat Completions, Anthropic Messages (Claude Code), and OpenAI Responses (Codex). Use the same Account → API key. Point the client at https://api.ashna.ai/v1/api and set model to a foundation model id or your Ashna custom agent id.

Base URL (all protocols)

Use this as baseURL, OPENAI_BASE_URL, or ANTHROPIC_BASE_URL. Clients append their own path: /chat/completions, /v1/messages, or /responses.

https://api.ashna.ai/v1/api

OpenAI Chat Completions

POST /chat/completions

Cursor, VS Code, Cline, Continue, and the OpenAI / Vercel AI SDKs. Cursor walkthrough

Anthropic Messages

POST /v1/messages

Claude Code and OpenClaw in anthropic-messages mode. Integration example · Full Claude Code guide

OpenAI Responses

POST /responses

Codex CLI and OpenClaw in openai-responses mode. Codex walkthrough

API keys

Create and manage keys in Account → API. OpenAI-style clients send Authorization: Bearer <your_key>. Claude Code also accepts x-api-key: <your_key>.

What's supported

Three request shapes on the same host. Chat Completions is verified with ai + @ai-sdk/openai. Claude Code posts Anthropic Messages. Codex posts OpenAI Responses.

  • OpenAI Chat Completions — POST /chat/completions (Cursor, VS Code, Cline, Continue, SDKs)
  • Anthropic Messages — POST /v1/messages (Claude Code)
  • OpenAI Responses — POST /responses (Codex)
  • Foundation models via model (for example glm-5.3, claude-sonnet-5, claude-opus-5, claude-fable-5, gpt-4o-mini, Ashna models)
  • Custom Ashna agents via model or agent_id (server-side multi-step tools)
  • Client tools (tools / tool_choice) with tool_calls round-trips
  • Sampling: temperature, top_p / top_k, penalties, stop, seed, max_tokens / max_completion_tokens
  • Structured output: response_format json_object and json_schema
  • OpenAI-compatible streaming SSE ([DONE], usage, tool call deltas)
  • Optional Ashna UI data stream via streamType: "data"
  • Vision images and PDF attachments (provider-aware: native PDF vs text extract)
  • OpenAI error envelope { error: { message, type, code, param } }
  • GET /models catalog

Quickstart

Create a key, then call Chat Completions with an OpenAI-compatible client — or point Claude Code at the same host with ANTHROPIC_BASE_URL.

1. Get your API key

Open Account → API on app.ashna.ai and create a key.

2. Make your first request

Set model to a foundation model id or your custom agent id from the Ashna app. Use the examples on the right.

Vercel AI SDK
import { createOpenAI } from '@ai-sdk/openai';
import { generateText } from 'ai';
const ashnaAI = createOpenAI({
baseURL: 'https://api.ashna.ai/v1/api'//api.ashna.ai/v1/api',
apiKey: process.env.ASHNA_API_KEY,
});
const { text } = await generateText({
model: ashnaAI.chat("gpt-4o-mini"),
messages: [
{ role: 'user', content: "Hello, can you help me?" }
],
maxOutputTokens: 500,
temperature: 0.7,
});
console.log(text);

Model IDs & agent IDs

Chat Completions uses a single model field. Pass either a foundation model id or your custom agent id. You can also send agent_id when model is omitted.

Foundation modelId

A catalog id for a built-in Ashna / provider model (for example glm-5.3, claude-sonnet-5, claude-opus-5, claude-fable-5, ashna-x1). Use this when you want a raw model without your custom agent prompt/tools.

Where to find it:

  • Live supported model ids listed below on this page
  • Authenticated OpenAI list: GET /v1/api/models
  • In the Ashna app model picker — the selected model's id is what the API expects

Custom agentId

Your Ashna agent's customAgentId (slug). When you pass this as model, Ashna loads that agent's system prompt, tools, and data sources and runs them server-side.

Where to find it:

  • Open the agent in app.ashna.ai → Agent Hub / agent info → Custom agent id (copy button)
  • From the browser URL when chatting with the agent — look for ?agent=<customAgentId>
  • In the agent builder, the generated agent id shown under the agent name

Example: { "model": "my-support-agent-8k2qv" } or { "agent_id": "my-support-agent-8k2qv" }.

Supported foundation model ids

Use any of these values as model for foundation-model Chat Completions. Grouped by provider family (OpenAI, Anthropic, DeepSeek, Google, and others).

Showing 69 of 69 supported model ids, grouped by provider.

Anthropic (7)

claude-fable-5claude-haiku-4.5claude-opus-4.1claude-opus-4.5claude-opus-5claude-sonnet-4.5claude-sonnet-5

Ashna (2)

ashna-diffusion-1ashna-x1

DeepSeek (3)

deepseek-v4-flashdeepseek-v4-prodeepseek-v4.1-flash

GLM (6)

glm-4.7glm-5glm-5.1glm-5.2glm-5.3glm-5.3-flash

Google (9)

gemini-2.0-flashgemini-2.5-Flashgemini-2.5-Flash-Litegemini-2.5-Progemini-3-Flash-Previewgemini-3-Progemini-3.1-Flash-Litegemini-3.1-Progemini-3.5-Flash

Inception Lab (1)

inkling

Kimi (5)

kimi-2.6kimi-k2-thinkingkimi-k2.5-thinkingkimi-k2.7-codekimi-k3

Meta (2)

llama-3.3 70Bllama-4-scout

Mistral (3)

mistral-3b-latestmistral-large-3mistral-open-8.22B

NVIDIA (1)

nemotron-ultra

OpenAI (27)

gpt-3.5-turbogpt-4.1gpt-4.1-minigpt-4.1-nanogpt-4ogpt-4o-minigpt-5gpt-5-codexgpt-5-minigpt-5.1gpt-5.1-codexgpt-5.2gpt-5.2-codexgpt-5.2-thinkinggpt-5.3-codexgpt-5.4gpt-5.4-thinkinggpt-5.5gpt-5.6-lunagpt-5.6-solgpt-5.6-terragpt-6-astragpt-o1gpt-o3-minigpt-o4-minigpt-oss-120bgpt-oss-20b

xAI (3)

grok-4-1-non-reasoninggrok-4-reasoninggrok-4.3

Authentication

All requests need the key from Account → API. OpenAI-compatible clients send a Bearer token. Claude Code sends the same secret as ANTHROPIC_API_KEY / x-api-key.

Authorizationstring

Bearer YOUR_API_KEY — Chat Completions, Responses, and GET /models

x-api-keystring

Same secret. Claude Code and other Anthropic Messages clients send this header.

Content-Typestring

application/json for POST bodies

OpenAI-style header
curl https://api.ashna.ai/v1/api/models \
-H "Authorization: Bearer YOUR_API_KEY"
Claude Code / Anthropic header
curl https://api.ashna.ai/v1/api/v1/messages \
-H "x-api-key: YOUR_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json"

Try the API

Paste a key from Account → API, choose a model or agent id, and send a live Chat Completions request. Your key stays in this browser tab only.

Response

Send a request to see the assistant reply and OpenAI-compatible JSON here.

Errors

Failures return an OpenAI-compatible envelope so SDKs can surface error.message consistently.

400
Bad Request

Invalid JSON, empty messages, or invalid params

401
Unauthorized

Missing or invalid API key

403
Forbidden

Model / entitlement not allowed for this key

404
Not Found

Unknown model or agent id

429
Rate Limit

Too many requests

500
Server Error

Unexpected failure while processing the request

Error envelope
{
"error": {
"message": "Invalid API key provided.",
"type": "invalid_request_error",
"code": "invalid_api_key",
"param": null
}
}

API Endpoints

Primary integration path is OpenAI Chat Completions. Paths below are relative to https://api.ashna.ai/v1/api.

List Models

Returns foundation models available through the external API (OpenAI { object: "list", data } shape). Custom agents are not listed here—use your agent's customAgentId directly as model (see Model & agent IDs).

GET/v1/api/models
cURL
curl https://api.ashna.ai/v1/api/models \
-H "Authorization: Bearer YOUR_API_KEY"
Response
{
"object": "list",
"data": [
{
"id": "gpt-4o-mini",
"object": "model",
"created": 1704369000,
"owned_by": "openai"
}
]
}

Chat Completions

Stateless OpenAI-compatible chat endpoint. Works with the OpenAI SDKs, Vercel AI SDK (generateText / streamText), Cursor, VS Code, Cline, and Continue. Claude Code does not use this path — it posts Anthropic Messages.

POST/v1/api/chat/completions

Key parameters

modelstring

Foundation model id or Ashna custom agent id. Alias: agent_id when model is omitted.

messagesarray

OpenAI messages (system, user, assistant, tool). Also accepts input or a string prompt.

systemstring

Optional top-level system instructions (merged with message-role system content).

streamboolean

true → OpenAI SSE chunks ending with [DONE]. Omit / false → JSON chat.completion.

streamType"text" | "data"

Default text (OpenAI SSE). Use data for Ashna UI-message data streams (agent tool progress). Not OpenAI chunk format.

max_tokensnumber

Max output tokens. Also: max_completion_tokens, maxTokens, maxOutputTokens.

Vercel AI SDK
import { createOpenAI } from '@ai-sdk/openai';
import { generateText } from 'ai';
const ashnaAI = createOpenAI({
baseURL: 'https://api.ashna.ai/v1/api'//api.ashna.ai/v1/api',
apiKey: process.env.ASHNA_API_KEY,
});
const { text } = await generateText({
model: ashnaAI.chat("gpt-4o-mini"),
messages: [
{ role: 'system', content: "You are a helpful assistant." },
{ role: 'user', content: "Explain quantum computing briefly." }
],
maxOutputTokens: 500,
temperature: 0.7,
});
console.log(text);
Response
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1704369000,
"model": "gpt-4o-mini",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Quantum computing leverages quantum mechanics..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 120,
"total_tokens": 145
}
}

Messages (Claude Code)

Anthropic Messages–compatible endpoint. Claude Code posts here — not Chat Completions. Set ANTHROPIC_BASE_URL to https://api.ashna.ai/v1/api so the CLI posts /v1/messages on that host. Use aliases sonnet, opus, haiku, or a catalog id such as glm-5.3-flash. Step-by-step install and first turn: How to use the AshnaAI API in Claude Code.

POST/v1/api/v1/messages
ANTHROPIC_BASE_URLenv

https://api.ashna.ai/v1/api. Do not drop /v1/api.

ANTHROPIC_API_KEYenv

The same secret from Account → API. Claude Code sends it as x-api-key.

modelstring

sonnet, opus, haiku, a dated Claude id, or any catalog / custom agent id.

messagesarray

Anthropic Messages array. Claude Code builds this for each turn.

max_tokensnumber

Required on raw HTTP calls. Claude Code sets this itself.

Full Claude Code walkthrough

Install the CLI, export both variables, and run the first turn in How to use the AshnaAI API in Claude Code.
Point Claude Code at AshnaAI
export ANTHROPIC_BASE_URL="https://api.ashna.ai/v1/api"
export ANTHROPIC_API_KEY="YOUR_API_KEY"
cd /path/to/your/project
claude
Raw Messages request
curl https://api.ashna.ai/v1/api/v1/messages \
-H "x-api-key: YOUR_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "sonnet",
"max_tokens": 256,
"messages": [
{ "role": "user", "content": "Reply with exactly: ping" }
]
}'
Response (Anthropic shape)
{
"id": "msg_abc123",
"type": "message",
"role": "assistant",
"model": "sonnet",
"content": [
{ "type": "text", "text": "ping" }
],
"stop_reason": "end_turn",
"usage": { "input_tokens": 12, "output_tokens": 1 }
}

Responses (Codex)

OpenAI Responses–compatible endpoint. Codex CLI posts here — not Chat Completions. Set OPENAI_BASE_URL to https://api.ashna.ai/v1/api. OpenClaw can use the same path in openai-responses mode. Install and first turn: How to use the AshnaAI API in OpenClaw, Cline, and Codex.

POST/v1/api/responses
OPENAI_BASE_URLenv

https://api.ashna.ai/v1/api

OPENAI_API_KEYenv

Bearer secret from Account → API.

modelstring

Catalog id such as glm-5.3-flash or a custom agent id.

inputstring | array

Responses input. Codex builds this for each turn.

Point Codex at AshnaAI
export OPENAI_BASE_URL="https://api.ashna.ai/v1/api"
export OPENAI_API_KEY="YOUR_API_KEY"
cd /path/to/your/project
codex
Raw Responses request
curl https://api.ashna.ai/v1/api/responses \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "glm-5.3-flash",
"input": "Reply with exactly: ping"
}'

Agents

Pass your Ashna custom agent id as model (or agent_id). The API loads that agent's prompt, foundation model, data sources, and tools, then runs a multi-step tool loop on the server (up to 200 steps)—similar to the Ashna web agent.

modelstring

Your custom agent id from the Ashna app (for example my-agent-abc12).

agent_idstring

Alias used when model is omitted.

Default streaming behavior

With stream: true (and default streamType: "text"), you receive OpenAI text SSE. Agent tools execute server-side; intermediate tool I/O is not forwarded as OpenAI chunks—only assistant text (and usage).

Ashna data stream

Set stream: true and streamType: "data" to receive the Ashna UI-message data stream (tool progress). This is not OpenAI Chat Completions SSE—use an Ashna/AI SDK UI stream consumer, not a plain OpenAI SSE parser.
Vercel AI SDK
import { createOpenAI } from '@ai-sdk/openai';
import { generateText } from 'ai';
const ashnaAI = createOpenAI({
baseURL: 'https://api.ashna.ai/v1/api'//api.ashna.ai/v1/api',
apiKey: process.env.ASHNA_API_KEY,
});
const { text } = await generateText({
model: ashnaAI.chat("your-custom-agent-id"),
messages: [
{ role: 'user', content: "Summarize today's priorities." }
],
maxOutputTokens: 400,
temperature: 0.7,
});
console.log(text);
Agent via agent_id (alias)
curl https://api.ashna.ai/v1/api/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"agent_id": "your-custom-agent-id",
"messages": [
{ "role": "user", "content": "Hello" }
]
}'

Tools

Two modes:

  • Client tools — send OpenAI tools / tool_choice on a foundation model. The API returns tool_calls (no server execute). You run the tool locally and send a follow-up with role: "tool" messages.
  • Agent tools — when model is a custom agent, configured tools run on the server across multiple steps.
Vercel AI SDK — client tools
import { createOpenAI } from '@ai-sdk/openai';
import { generateText, jsonSchema, tool } from 'ai';
const ashnaAI = createOpenAI({
baseURL: 'https://api.ashna.ai/v1/api'//api.ashna.ai/v1/api',
apiKey: process.env.ASHNA_API_KEY,
});
const weather = tool({
description: 'Get weather for a city',
inputSchema: jsonSchema({
type: 'object',
properties: { city: { type: 'string' } },
required: ['city'],
}),
execute: async ({ city }) => ({ city, tempC: 21 }),
});
const first = await generateText({
model: ashnaAI.chat('gpt-4o-mini'),
tools: { get_weather: weather },
toolChoice: 'required',
prompt: 'What is the weather in Paris? Use the tool.',
});
// first.toolCalls → execute locally → send tool results back in messages

Sampling & JSON output

temperaturenumber

Sampling temperature. Some reasoning models reject non-default values; the API omits unsupported params automatically.

top_p / top_knumber

Nucleus / top-k sampling (aliases topP, topK).

frequency_penalty / presence_penaltynumber

OpenAI-style penalties (camelCase aliases accepted).

stopstring | string[]

Stop sequences.

seednumber

Best-effort deterministic sampling when the provider supports it.

response_formatobject

{ type: "json_object" } or { type: "json_schema", json_schema: { name, schema, ... } }.

json_object

openai (npm)
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env.ASHNA_API_KEY,
baseURL: 'https://api.ashna.ai/v1/api'//api.ashna.ai/v1/api',
});
const response = await client.chat.completions.create({
model: "gpt-4o-mini",
messages: [
{ role: 'user', content: "Return JSON with keys a=1 and b=\"x\"." }
],
temperature: 0.2,
max_tokens: 80,
response_format: {"type":"json_object"},});
console.log(response.choices[0].message.content);

json_schema

cURL
curl https://api.ashna.ai/v1/api/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "Return a city weather sample."
}
],
"temperature": 0.2,
"max_tokens": 120,
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "weather_sample",
"schema": {
"type": "object",
"additionalProperties": false,
"properties": {
"city": {
"type": "string"
},
"tempC": {
"type": "number"
}
},
"required": [
"city",
"tempC"
]
}
}
}
}'

Images & PDFs

User messages may include OpenAI/AI SDK multimodal parts. Ashna routes attachments per foundation model provider:

  • Images — kept as vision parts when the model allows image input; otherwise replaced with an explanatory text note.
  • Native PDF — Gemini, Claude, Bedrock, Mistral, and Azure/OpenAI Responses models receive PDF file parts.
  • PDF text extract — Azure Chat Completions (for example gpt-4o-mini), Groq, and many OpenAI-compatible hosts extract PDF text before the model call.
AI SDK — image + PDF
import { createOpenAI } from '@ai-sdk/openai';
import { generateText } from 'ai';
import { readFileSync } from 'fs';
const ashnaAI = createOpenAI({
baseURL: 'https://api.ashna.ai/v1/api'//api.ashna.ai/v1/api',
apiKey: process.env.ASHNA_API_KEY,
});
const pdfBytes = readFileSync('./report.pdf');
const result = await generateText({
model: ashnaAI.chat('gpt-4o-mini'),
messages: [
{
role: 'user',
content: [
{ type: 'text', text: 'Summarize this PDF and describe the image.' },
{ type: 'file', data: pdfBytes, mediaType: 'application/pdf', filename: 'report.pdf' },
{ type: 'image', image: readFileSync('./chart.png'), mediaType: 'image/png' },
],
},
],
});
Raw OpenAI image_url / file
{
"model": "gpt-4o-mini",
"messages": [
{
"role": "user",
"content": [
{ "type": "text", "text": "What is in this image and PDF?" },
{
"type": "image_url",
"image_url": { "url": "data:image/png;base64,..." }
},
{
"type": "file",
"file": {
"filename": "hello.pdf",
"file_data": "data:application/pdf;base64,..."
}
}
]
}
]
}

Streaming

Set stream: true for OpenAI-compatible SSE (chat.completion.chunk events, ending with data: [DONE]).

Vercel AI SDK
import { createOpenAI } from '@ai-sdk/openai';
import { streamText } from 'ai';
const ashnaAI = createOpenAI({
baseURL: 'https://api.ashna.ai/v1/api'//api.ashna.ai/v1/api',
apiKey: process.env.ASHNA_API_KEY,
});
const result = streamText({
model: ashnaAI.chat("gpt-4o-mini"),
messages: [
{ role: 'user', content: "Say hello in one short sentence." }
],
maxOutputTokens: 100,
temperature: 0.7,
});
for await (const chunk of result.textStream) {
process.stdout.write(chunk);
}
SSE shape
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"usage":{"prompt_tokens":12,"completion_tokens":4,"total_tokens":16}}
data: [DONE]

Completions (legacy alias)

POST /v1/api/completions uses the same pipeline as Chat Completions for SDK compatibility. Prefer /chat/completions. You can send prompt (string) or messages; the response shape is still a chat completion object from this shared pipeline.

POST/v1/api/completions
prompt alias
curl https://api.ashna.ai/v1/api/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini",
"prompt": "Reply with exactly: ping",
"max_tokens": 20
}'

Editor & CLI guides

Point Cursor, Claude Code, Codex, VS Code, Cline, OpenClaw, or Continue at https://api.ashna.ai/v1/api. Create a key in Account → API. Claude Code uses POST /v1/messages; Codex uses POST /responses; Cursor and VS Code use POST /chat/completions.

SDKs & Integrations

OpenAI SDKs talk Chat Completions — only the base URL and API key change. Claude Code is an Anthropic Messages client: export ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY, then see Messages (Claude Code) or the full walkthrough. Keys come from Account → API.

Install tips: npm i ai @ai-sdk/openai · npm i openai · pip install openai · go get github.com/openai/openai-go/v3 · OpenAI Java SDK via Maven/Gradle (com.openai:openai-java).

Vercel AI SDK
import { createOpenAI } from '@ai-sdk/openai';
import { generateText } from 'ai';
const ashnaAI = createOpenAI({
baseURL: 'https://api.ashna.ai/v1/api'//api.ashna.ai/v1/api',
apiKey: process.env.ASHNA_API_KEY,
});
const { text } = await generateText({
model: ashnaAI.chat("gpt-4o-mini"),
messages: [
{ role: 'user', content: "Hello!" }
],
maxOutputTokens: 100,
temperature: 0.2,
});
console.log(text);