Skip to content

Chat completions (OpenAI format)

POST
/v1/chat/completions
curl --request POST \
--url https://api.openpike.dev/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'x-openpike-no-log: 1' \
--header 'x-openpike-run: task-8841' \
--header 'x-openpike-run-max-usd: 5' \
--header 'x-openpike-tags: agent=reviewer,env=prod' \
--data '{ "model": "deepseek/deepseek-flash", "messages": [ { "role": "user", "content": "Say hello in five words." } ] }'

OpenAI’s chat completions format, for OpenAI, Google AI Studio, DeepSeek, OpenRouter and the other OpenAI-compatible providers. The body is passed through to the provider; only model is read and rewritten to the provider’s own model ID.

Streaming: with "stream": true the response is server-sent events, passed through as they arrive. OpenPike sets stream_options.include_usage for OpenAI-compatible providers (unless the provider rejects it), so the last chunk carries token usage.

Aliases: a model named openpike/<alias> tries the alias’s targets in order, falling back before the first byte on 429, 5xx, a network error or an unknown model, at most 3 attempts. x-openpike-model and x-openpike-attempts say which target answered.

x-openpike-tags
string

Example

agent=reviewer,env=prod

Comma-separated key=value pairs merged over the virtual key’s tags for this request, for example agent=reviewer,env=prod. At most 10 pairs; keys and values at most 64 characters. Not forwarded to the provider.

x-openpike-no-log
string
Allowed values: 1 true

1 or true keeps this request out of prompt logging even when the workspace has it on. Not forwarded to the provider.

x-openpike-run
string
>= 1 characters <= 128 characters

Example

task-8841

The run this request belongs to, 1 to 128 printable ASCII characters, for example a task or session ID. Run limits on matching budgets cap each run’s spend, requests and wall time; a run at a cap gets 429 run_limit_exceeded. Not forwarded to the provider.

x-openpike-run-label
string
<= 200 characters

A human name for the run, at most 200 characters. Needs x-openpike-run. Not forwarded.

x-openpike-run-max-usd
string

Example

5

A spend cap in dollars for the run, above zero. Only lowers a budget’s run spend cap. Needs x-openpike-run. Not forwarded.

Media typeapplication/json

OpenAI’s chat completions request. Only the fields OpenPike reads are listed; every other field is passed to the provider unchanged.

object
model
required

provider/model or openpike/<alias>.

string
messages
required
Array<object>
object
key
additional properties
any
stream
boolean
key
additional properties
any

Example

{
"model": "deepseek/deepseek-flash",
"messages": [
{
"role": "user",
"content": "Say hello in five words."
}
]
}

The provider’s response, passed through. JSON, or server-sent events when stream is true.

OpenAI’s chat completion object, as returned by the provider.

object
id
string
object
string
model
string
choices
Array<object>
object
key
additional properties
any
usage
object
key
additional properties
any
key
additional properties
any

Example

{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1794837742,
"model": "deepseek-flash",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello there, how are you?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 13,
"completion_tokens": 7,
"total_tokens": 20
}
}
x-openpike-request-id
string
Example
req_QhMBW1esl4VW2o8NXDEcOLsS

The request ID, also shown in Logs.

x-openpike-provider
string
Example
deepseek

The provider that served the request, or that returned an upstream error.

x-openpike-model
string
Example
deepseek/deepseek-flash

The provider/model that served the request; differs from the request for aliases.

x-openpike-attempts
integer
Example
1

Upstream attempts, 1 when no fallback happened.

server-timing
string
Example
gate;dur=4.2

gate;dur=<ms>: time spent checking budgets, pauses and plan limits.

invalid_request (body is not valid JSON, or not a JSON object), invalid_tags, invalid_model (not provider/model, unknown provider or alias), unsupported_format (the provider does not serve this endpoint’s format) or unsupported_parameter (background: true on /v1/responses).

Media typeapplication/json

The error shape of chat completions, Responses, System One and models.

object
error
required
object
type
required
string
Allowed value: openpike_error
code
required
string
Allowed values: invalid_virtual_key invalid_request invalid_tags invalid_model unsupported_format unsupported_parameter provider_disabled missing_provider_key budget_exceeded loop_detected scope_paused run_limit_exceeded plan_limit_reached plan_limit_throttled too_many_auth_failures upstream_unreachable upstream_error internal_error
message
required
string
request_id
required
string

Example

{
"error": {
"type": "openpike_error",
"code": "invalid_model",
"message": "Unknown provider \"deepsek\".",
"request_id": "req_..."
}
}
x-openpike-request-id
string
Example
req_QhMBW1esl4VW2o8NXDEcOLsS

The request ID, also shown in Logs.

invalid_virtual_key: missing, unknown or revoked virtual key, or a key disabled because the plan allows fewer keys.

Media typeapplication/json

The error shape of chat completions, Responses, System One and models.

object
error
required
object
type
required
string
Allowed value: openpike_error
code
required
string
Allowed values: invalid_virtual_key invalid_request invalid_tags invalid_model unsupported_format unsupported_parameter provider_disabled missing_provider_key budget_exceeded loop_detected scope_paused run_limit_exceeded plan_limit_reached plan_limit_throttled too_many_auth_failures upstream_unreachable upstream_error internal_error
message
required
string
request_id
required
string

Example

{
"error": {
"type": "openpike_error",
"code": "invalid_virtual_key",
"message": "The API key is invalid or revoked.",
"request_id": "req_..."
}
}
x-openpike-request-id
string
Example
req_QhMBW1esl4VW2o8NXDEcOLsS

The request ID, also shown in Logs.

provider_disabled: the provider is in the catalog but not enabled yet.

Media typeapplication/json

The error shape of chat completions, Responses, System One and models.

object
error
required
object
type
required
string
Allowed value: openpike_error
code
required
string
Allowed values: invalid_virtual_key invalid_request invalid_tags invalid_model unsupported_format unsupported_parameter provider_disabled missing_provider_key budget_exceeded loop_detected scope_paused run_limit_exceeded plan_limit_reached plan_limit_throttled too_many_auth_failures upstream_unreachable upstream_error internal_error
message
required
string
request_id
required
string

Example

{
"error": {
"type": "openpike_error",
"code": "invalid_virtual_key"
}
}

missing_provider_key: the workspace has no key for that provider.

Media typeapplication/json

The error shape of chat completions, Responses, System One and models.

object
error
required
object
type
required
string
Allowed value: openpike_error
code
required
string
Allowed values: invalid_virtual_key invalid_request invalid_tags invalid_model unsupported_format unsupported_parameter provider_disabled missing_provider_key budget_exceeded loop_detected scope_paused run_limit_exceeded plan_limit_reached plan_limit_throttled too_many_auth_failures upstream_unreachable upstream_error internal_error
message
required
string
request_id
required
string

Example

{
"error": {
"type": "openpike_error",
"code": "invalid_virtual_key"
}
}

An OpenPike block, before the provider is called: budget_exceeded, loop_detected, scope_paused, run_limit_exceeded, plan_limit_reached, plan_limit_throttled or too_many_auth_failures. A 429 from the provider itself comes back as upstream_error with the provider’s status.

Media typeapplication/json

The error shape of chat completions, Responses, System One and models.

object
error
required
object
type
required
string
Allowed value: openpike_error
code
required
string
Allowed values: invalid_virtual_key invalid_request invalid_tags invalid_model unsupported_format unsupported_parameter provider_disabled missing_provider_key budget_exceeded loop_detected scope_paused run_limit_exceeded plan_limit_reached plan_limit_throttled too_many_auth_failures upstream_unreachable upstream_error internal_error
message
required
string
request_id
required
string

Example

{
"error": {
"type": "openpike_error",
"code": "budget_exceeded",
"message": "The hard budget for agent=reviewer is used up for this period.",
"request_id": "req_..."
}
}
retry-after
integer

Seconds until the request may succeed. Set on OpenPike’s 429 blocks, and passed through from the provider on upstream errors.

x-openpike-request-id
string
Example
req_QhMBW1esl4VW2o8NXDEcOLsS

The request ID, also shown in Logs.

upstream_unreachable (502): the provider could not be reached. upstream_error: the provider returned an error; its status code is passed through (so it may be any 4xx or 5xx) with its message, after anything that looks like a key is removed.

Media typeapplication/json

The error shape of chat completions, Responses, System One and models.

object
error
required
object
type
required
string
Allowed value: openpike_error
code
required
string
Allowed values: invalid_virtual_key invalid_request invalid_tags invalid_model unsupported_format unsupported_parameter provider_disabled missing_provider_key budget_exceeded loop_detected scope_paused run_limit_exceeded plan_limit_reached plan_limit_throttled too_many_auth_failures upstream_unreachable upstream_error internal_error
message
required
string
request_id
required
string

Example

{
"error": {
"type": "openpike_error",
"code": "invalid_virtual_key"
}
}
x-openpike-provider
string
Example
deepseek

The provider that served the request, or that returned an upstream error.