Skip to content

Chat Completions API

OpenAI-compatible chat completions endpoint covering every chat and reasoning model on the platform — see Models for the current list. Supports streaming, function calling, vision, and structured outputs.

Base URL: https://api.jarvisclaw.ai/v1

Authentication

Both methods are supported — all requests settle via x402 on-chain:

MethodHeaderDescription
API KeyAuthorization: Bearer sk-...Platform signs x402 from your HD wallet automatically
Private Key (x402)Automatic via SDKAgent signs x402 directly from its own wallet

See Agent Payments (x402) for full details on how both methods work.

Endpoints

POST /v1/chat/completions

Create a chat completion.

Headers

HeaderRequiredDescription
AuthorizationConditionalBearer sk-your-api-key. Omit when paying via x402
Content-TypeYesMust be application/json
PAYMENT-SIGNATUREConditionalBase64-encoded x402 payment payload (required after 402, x402 v2). X-PAYMENT is accepted as an alias

Body Parameters

ParameterTypeRequiredDescription
modelstringYesModel ID (e.g., openai/gpt-5.5)
messagesarrayYesArray of message objects
max_tokensintegerNoMaximum tokens to generate (default: 1024)
max_completion_tokensintegerNoMax output tokens including reasoning (for o-series / reasoning models)
temperaturenumberNoSampling temperature (0-2)
top_pnumberNoNucleus sampling parameter
top_kintegerNoTop-K sampling (provider-dependent)
streambooleanNoStream partial responses via SSE (default: false)
stream_optionsobjectNo{"include_usage": true} to receive token counts in stream
stopstring or arrayNoStop sequence(s)
nintegerNoNumber of completions to generate (default: 1)
frequency_penaltynumberNoPenalize repeated tokens (-2.0 to 2.0)
presence_penaltynumberNoPenalize tokens already present (-2.0 to 2.0)
toolsarrayNoList of tool/function definitions for function calling
tool_choicestring or objectNoControls tool use: "auto", "none", or specific tool
parallel_tool_callsbooleanNoWhether to run tool calls in parallel (default: true)
response_formatobjectNo{"type": "json_object"} or {"type": "json_schema", "json_schema": {...}}
seednumberNoDeterministic sampling seed
reasoning_effortstringNo"low", "medium", or "high" — controls thinking depth (o-series models)
logprobsbooleanNoReturn log probabilities of output tokens
top_logprobsintegerNoNumber of top logprobs per token (0-20)
prompt_cachebooleanNoEnable prompt caching on Anthropic models
logit_biasobjectNoToken ID to bias value mapping (-100 to 100)
userstringNoUnique end-user identifier
service_tierstringNoService level preference (e.g., "default", "flex"). Controls quality/speed tradeoff for supported models
modalitiesarrayNoOutput modalities: ["text"] or ["text", "audio"]
audioobjectNoAudio output config: {"voice": "alloy", "format": "wav"}. Requires modalities to include "audio"
storebooleanNoWhether to store this request for model distillation/evals (OpenAI). Default: allowed to pass through
metadataobjectNoArbitrary key-value metadata attached to the request
predictionobjectNoPredicted output for speculative decoding (OpenAI)
web_search_optionsobjectNoWeb search configuration for grounded responses (Claude/xAI)

Provider-Specific Parameters

These parameters are transparently forwarded to the upstream provider when applicable:

ParameterProviderDescription
enable_thinkingQwenEnable extended thinking mode
thinkOllamaEnable thinking/reasoning output
enable_searchQwenEnable web search augmentation
search_parametersxAI (Grok)Search configuration for grounded responses
vl_high_resolution_imagesQwen-VLEnable high-resolution image processing
reasoning_splitMinimaxControl reasoning output splitting

Message Object

FieldTypeDescription
rolestringOne of: system, user, assistant, tool
contentstring or arrayThe message content (string or content parts for vision)
namestringOptional name for the participant
tool_callsarrayTool calls made by the assistant (assistant messages only)
tool_call_idstringID of the tool call this message responds to (tool messages only)

Request Example

json
{
  "model": "anthropic/claude-sonnet-4.6",
  "messages": [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Explain quantum computing in simple terms."}
  ],
  "max_tokens": 1024,
  "temperature": 0.7,
  "stream": true
}

Response Example

json
{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1717200000,
  "model": "anthropic/claude-sonnet-4.6",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Quantum computing uses quantum bits (qubits)..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 24,
    "completion_tokens": 156,
    "total_tokens": 180
  }
}

Usage Fields

FieldAlways presentNotes
prompt_tokensyesFull prompt size; cache reads already folded in
completion_tokensyesOutput tokens; includes thinking/reasoning for all providers
total_tokensyesSum of prompt + completion
prompt_tokens_details.cached_tokenswhen cache hitPrompt tokens read from cache (OpenAI convention)
prompt_tokens_details.cached_creation_tokenswhen cache writePrompt tokens written to cache this turn (JarvisClaw extension)
cache_read_input_tokenswhen cache hitSame as prompt_tokens_details.cached_tokens — Anthropic/Bedrock native label
cache_creation_input_tokenswhen cache writeSame as prompt_tokens_details.cached_creation_tokens — Anthropic/Bedrock native label
completion_tokens_details.reasoning_tokenswhen reasoningOpenAI GPT-5.x / o-series only; forwarded verbatim. Not available for Anthropic/Bedrock (thinking tokens already included in completion_tokens)

Protocol naming convention:

  • Claude native /v1/messages: usage.input_tokens, usage.output_tokens, usage.cache_creation_input_tokens, usage.cache_read_input_tokens
  • OpenAI-compat /v1/chat/completions: usage.prompt_tokens_details.cached_tokens (reads), usage.prompt_tokens_details.cached_creation_tokens (writes), usage.completion_tokens_details.reasoning_tokens (reasoning)

Enabling prompt caching on Anthropic models: Pass "prompt_cache": true in the request body, or embed cache_control blocks in your message content directly — both are honored.

Payment Required (402)

When you first make a request without payment (x402 mode), you'll receive an x402 v2 challenge:

json
{
  "x402Version": 2,
  "accepts": [
    {
      "scheme": "exact",
      "network": "eip155:8453",
      "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
      "amount": "1000",
      "payTo": "0x<seller-address>",
      "maxTimeoutSeconds": 300,
      "extra": { "name": "USD Coin", "version": "2" }
    }
  ],
  "facilitator": "https://api.cdp.coinbase.com/platform/v2/x402",
  "resource": {
    "url": "https://api.jarvisclaw.ai/v1/chat/completions",
    "description": "Chat completion",
    "mimeType": "application/json",
    "tag": "ai-model"
  },
  "extensions": { "bazaar": { "info": {}, "schema": {} } }
}

amount is in the token's smallest unit — for USDC that is 6 decimals, so 1000 = $0.001. The same payload is also returned base64-encoded in the PAYMENT-REQUIRED response header.

402 is the normal flow, not an error — the first request returns a price quote. Sign it and retry with the PAYMENT-SIGNATURE header (or X-PAYMENT, which is accepted as an alias) to get your completion. The SDKs do this round-trip automatically. See Agent Payments (x402) for the full signing walkthrough.

Pricing

Derived from each model's ratio: input = ratio × $2/M tokens, output = input × completion ratio.

ModelInput / 1MOutput / 1M
openai/gpt-5.5$5.00$30.00
anthropic/claude-sonnet-4.6$3.00$15.00
google/gemini-2.5-pro$1.25$10.00
deepseek/deepseek-chat$0.20$0.40
xai/grok-4.3$1.50$4.00
nvidia/*freefree

Full ratio table: Models. Live figures: api.jarvisclaw.ai/pricing.

Code Examples

bash
curl -X POST https://api.jarvisclaw.ai/v1/chat/completions \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-4.6",
    "messages": [
      {"role": "user", "content": "Hello, how are you?"}
    ],
    "stream": true
  }'
python
from openai import OpenAI

client = OpenAI(
    base_url="https://api.jarvisclaw.ai/v1",
    api_key="sk-your-api-key",
)

# Simple completion
response = client.chat.completions.create(
    model="anthropic/claude-sonnet-4.6",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Explain quantum computing."},
    ],
)
print(response.choices[0].message.content)

# Streaming
stream = client.chat.completions.create(
    model="anthropic/claude-sonnet-4.6",
    messages=[{"role": "user", "content": "Tell me a joke."}],
    stream=True,
)
for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")
python
from jarvisclaw import ChatClient

# ─── Option A: Base chain (EVM) ───
# Hex private key → USDC on Base (Chain ID 8453)
chat = ChatClient(private_key="0x<evm-private-key>")

# ─── Option B: Solana ───
# Base58 keypair → USDC SPL on Solana mainnet
# chat = ChatClient(private_key="<solana-bs58-keypair>")

# SDK auto-detects chain from key format — no config needed

# Simple completion (smart route — auto-selects best model)
response = chat.complete("Explain quantum computing.")
print(response)

# With explicit model
response = chat.complete("Explain quantum computing.", model="anthropic/claude-sonnet-4.6")
print(response)

# Streaming
for chunk in chat.stream("Tell me a joke.", model="openai/gpt-5.4-mini"):
    print(chunk, end="")
go
package main

import (
    "context"
    "fmt"
    jc "github.com/api-jarvisclaw/go-sdk/v2"
)

func main() {
    ctx := context.Background()
    cc, _ := jc.NewChatClient(jc.WithAPIKey("sk-your-api-key"))

    // Simple completion
    response, _ := cc.Complete(ctx, "Explain quantum computing.",
        jc.WithChatModel("anthropic/claude-sonnet-4.6"))
    fmt.Println(response)

    // Streaming
    stream, _ := cc.Stream(ctx, "Tell me a joke.", jc.WithChatModel("openai/gpt-5.4-mini"))
    for chunk := range stream.Channel() {
        fmt.Print(chunk)
    }
}
go
package main

import (
    "context"
    "fmt"
    jc "github.com/api-jarvisclaw/go-sdk/v2"
)

func main() {
    ctx := context.Background()

    // x402 Agent wallet — pays per-call via USDC on Base (Chain ID 8453)
    cc, _ := jc.NewChatClient(jc.WithPrivateKey("0x<evm-private-key>"))

    // Simple completion (smart route — auto-selects best model)
    response, _ := cc.Complete(ctx, "Explain quantum computing.")
    fmt.Println(response)

    // With explicit model
    response, _ = cc.Complete(ctx, "Explain quantum computing.",
        jc.WithChatModel("anthropic/claude-sonnet-4.6"))
    fmt.Println(response)

    // Streaming
    stream, _ := cc.Stream(ctx, "Tell me a joke.", jc.WithChatModel("openai/gpt-5.4-mini"))
    for chunk := range stream.Channel() {
        fmt.Print(chunk)
    }
}