Completions API
This page documents the 4 gateway endpoints tagged completions in the gateway's OpenAPI document. Every example targets a gateway on http://localhost:4000 and authenticates with the SPANWAY_API_KEY environment variable, which holds the master key or a virtual key that has access to the route. Request and response fields are taken from the schema the running gateway publishes at /openapi.json, and the same document is bundled with this site as openapi.json.
| Method | Path | Summary |
|---|---|---|
| POST | /openai/deployments/{model}/completions | Create a text completion |
| POST | /engines/{model}/completions | Create a text completion |
| POST | /completions | Create a text completion |
| POST | /v1/completions | Create a text completion |
Endpoints
POST /openai/deployments/{model}/completions
Create a text completion
Continue a plain text prompt, in the legacy OpenAI completions format, for older clients and instruct models. New integrations should use chat completions. Any virtual key that may use the named model can call it. The gateway checks the key's budget, rate limits and guardrails first, sends the request to one of the model group's deployments with retries and fallbacks, and records the cost and usage in the spend logs. Nothing else changes.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
model | path | string or null | Yes | |
x-spanway-routing-skips | header | enum: "true" | No | Send true to get the candidates the router skipped in the answer headers. See https://docs.spanway.ai/docs/proxy/routing_headers |
Request body (application/json, object):
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model |
prompt | string or array of string | Yes | Prompt |
max_tokens | integer or null | No | Max Tokens |
temperature | number or null | No | Temperature |
top_p | number or null | No | Top P |
n | integer or null | No | N |
stream | boolean or null | No | Stream |
stop | string or array of string or null | No | Stop |
logprobs | integer or null | No | Logprobs |
echo | boolean or null | No | Echo |
suffix | string or null | No | Suffix |
presence_penalty | number or null | No | Presence Penalty |
frequency_penalty | number or null | No | Frequency Penalty |
best_of | integer or null | No | Best Of |
logit_bias | object or null | No | Logit Bias |
user | string or null | No | User |
Example request:
curl -X POST "http://localhost:4000/openai/deployments/model-123/completions" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-3.5-turbo-instruct",
"prompt": "def fibonacci(n):",
"max_tokens": 120,
"temperature": 0
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The completion in the OpenAI text completion shape. | application/json object |
| 400 | The request is invalid, for example a missing or unsupported parameter, a prompt longer than the model's context window, content a guardrail or the provider refused, or no deployment that satisfies the data policy of the key, team or organization (No deployment of model 'gpt-5.5' satisfies the data policy: ...). error.message says which. | application/json ProxyError |
| 401 | No valid key was sent, or the key has expired or is blocked. | application/json ProxyError |
| 403 | The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403. | application/json ProxyError |
| 404 | The route or resource does not exist, or this key cannot see it. An unknown model name is a 400 (Invalid model name passed in model=...). | application/json ProxyError |
| 408 | The provider did not answer before the request timed out. | application/json ProxyError |
| 413 | The request body is larger than max_request_size_mb (100 MB by default), or an upload is larger than its own limit. The gateway refused it before reading the key. Docs | application/json object |
| 422 | The request body does not have the expected shape, or a budget (key, user, team, organization or end user) is used up: error.type is budget_exceeded. The budget status is spanway_settings.budget_exceeded_status_code, 422 by default. With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError or HTTPValidationError |
| 429 | Too many requests. A provider limit or a gateway limit (requests or tokens per minute, or parallel requests) refused the call, and error.type says which. A gateway limit also sends the RateLimit headers and x-spanway-rate-limited-by. Docs With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError |
| 500 | The gateway or the provider failed unexpectedly, or the gateway could not reach the provider. Retry, and quote the request id if it keeps failing. | application/json ProxyError |
| 502 | The provider, or a proxy in front of it, answered with something that is not a valid response. | application/json ProxyError |
| 503 | The provider is overloaded or unavailable. With Redis rate limiting, a 503 also means the gateway could not check the rate limit counters and refused the request, because fail_closed_rate_limit_enforcement is on. Docs | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Id |
object | string | Yes | Object |
created | integer | Yes | Created |
model | string or null | Yes | Model |
choices | array of object | Yes | Choices |
usage | object or null | Yes |
POST /engines/{model}/completions
Create a text completion
Continue a plain text prompt, in the legacy OpenAI completions format, for older clients and instruct models. New integrations should use chat completions. Any virtual key that may use the named model can call it. The gateway checks the key's budget, rate limits and guardrails first, sends the request to one of the model group's deployments with retries and fallbacks, and records the cost and usage in the spend logs. Nothing else changes.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
model | path | string or null | Yes | |
x-spanway-routing-skips | header | enum: "true" | No | Send true to get the candidates the router skipped in the answer headers. See https://docs.spanway.ai/docs/proxy/routing_headers |
Request body (application/json, object):
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model |
prompt | string or array of string | Yes | Prompt |
max_tokens | integer or null | No | Max Tokens |
temperature | number or null | No | Temperature |
top_p | number or null | No | Top P |
n | integer or null | No | N |
stream | boolean or null | No | Stream |
stop | string or array of string or null | No | Stop |
logprobs | integer or null | No | Logprobs |
echo | boolean or null | No | Echo |
suffix | string or null | No | Suffix |
presence_penalty | number or null | No | Presence Penalty |
frequency_penalty | number or null | No | Frequency Penalty |
best_of | integer or null | No | Best Of |
logit_bias | object or null | No | Logit Bias |
user | string or null | No | User |
Example request:
curl -X POST "http://localhost:4000/engines/model-123/completions" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-3.5-turbo-instruct",
"prompt": "def fibonacci(n):",
"max_tokens": 120,
"temperature": 0
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The completion in the OpenAI text completion shape. | application/json object |
| 400 | The request is invalid, for example a missing or unsupported parameter, a prompt longer than the model's context window, content a guardrail or the provider refused, or no deployment that satisfies the data policy of the key, team or organization (No deployment of model 'gpt-5.5' satisfies the data policy: ...). error.message says which. | application/json ProxyError |
| 401 | No valid key was sent, or the key has expired or is blocked. | application/json ProxyError |
| 403 | The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403. | application/json ProxyError |
| 404 | The route or resource does not exist, or this key cannot see it. An unknown model name is a 400 (Invalid model name passed in model=...). | application/json ProxyError |
| 408 | The provider did not answer before the request timed out. | application/json ProxyError |
| 413 | The request body is larger than max_request_size_mb (100 MB by default), or an upload is larger than its own limit. The gateway refused it before reading the key. Docs | application/json object |
| 422 | The request body does not have the expected shape, or a budget (key, user, team, organization or end user) is used up: error.type is budget_exceeded. The budget status is spanway_settings.budget_exceeded_status_code, 422 by default. With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError or HTTPValidationError |
| 429 | Too many requests. A provider limit or a gateway limit (requests or tokens per minute, or parallel requests) refused the call, and error.type says which. A gateway limit also sends the RateLimit headers and x-spanway-rate-limited-by. Docs With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError |
| 500 | The gateway or the provider failed unexpectedly, or the gateway could not reach the provider. Retry, and quote the request id if it keeps failing. | application/json ProxyError |
| 502 | The provider, or a proxy in front of it, answered with something that is not a valid response. | application/json ProxyError |
| 503 | The provider is overloaded or unavailable. With Redis rate limiting, a 503 also means the gateway could not check the rate limit counters and refused the request, because fail_closed_rate_limit_enforcement is on. Docs | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Id |
object | string | Yes | Object |
created | integer | Yes | Created |
model | string or null | Yes | Model |
choices | array of object | Yes | Choices |
usage | object or null | Yes |
POST /completions
Create a text completion
Continue a plain text prompt, in the legacy OpenAI completions format, for older clients and instruct models. New integrations should use chat completions. Any virtual key that may use the named model can call it. The gateway checks the key's budget, rate limits and guardrails first, sends the request to one of the model group's deployments with retries and fallbacks, and records the cost and usage in the spend logs. Nothing else changes.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
model | query | string or null | No | |
x-spanway-routing-skips | header | enum: "true" | No | Send true to get the candidates the router skipped in the answer headers. See https://docs.spanway.ai/docs/proxy/routing_headers |
Request body (application/json, object):
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model |
prompt | string or array of string | Yes | Prompt |
max_tokens | integer or null | No | Max Tokens |
temperature | number or null | No | Temperature |
top_p | number or null | No | Top P |
n | integer or null | No | N |
stream | boolean or null | No | Stream |
stop | string or array of string or null | No | Stop |
logprobs | integer or null | No | Logprobs |
echo | boolean or null | No | Echo |
suffix | string or null | No | Suffix |
presence_penalty | number or null | No | Presence Penalty |
frequency_penalty | number or null | No | Frequency Penalty |
best_of | integer or null | No | Best Of |
logit_bias | object or null | No | Logit Bias |
user | string or null | No | User |
Example request:
curl -X POST "http://localhost:4000/completions" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-3.5-turbo-instruct",
"prompt": "def fibonacci(n):",
"max_tokens": 120,
"temperature": 0
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The completion in the OpenAI text completion shape. | application/json object |
| 400 | The request is invalid, for example a missing or unsupported parameter, a prompt longer than the model's context window, content a guardrail or the provider refused, or no deployment that satisfies the data policy of the key, team or organization (No deployment of model 'gpt-5.5' satisfies the data policy: ...). error.message says which. | application/json ProxyError |
| 401 | No valid key was sent, or the key has expired or is blocked. | application/json ProxyError |
| 403 | The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403. | application/json ProxyError |
| 404 | The route or resource does not exist, or this key cannot see it. An unknown model name is a 400 (Invalid model name passed in model=...). | application/json ProxyError |
| 408 | The provider did not answer before the request timed out. | application/json ProxyError |
| 413 | The request body is larger than max_request_size_mb (100 MB by default), or an upload is larger than its own limit. The gateway refused it before reading the key. Docs | application/json object |
| 422 | The request body does not have the expected shape, or a budget (key, user, team, organization or end user) is used up: error.type is budget_exceeded. The budget status is spanway_settings.budget_exceeded_status_code, 422 by default. With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError or HTTPValidationError |
| 429 | Too many requests. A provider limit or a gateway limit (requests or tokens per minute, or parallel requests) refused the call, and error.type says which. A gateway limit also sends the RateLimit headers and x-spanway-rate-limited-by. Docs With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError |
| 500 | The gateway or the provider failed unexpectedly, or the gateway could not reach the provider. Retry, and quote the request id if it keeps failing. | application/json ProxyError |
| 502 | The provider, or a proxy in front of it, answered with something that is not a valid response. | application/json ProxyError |
| 503 | The provider is overloaded or unavailable. With Redis rate limiting, a 503 also means the gateway could not check the rate limit counters and refused the request, because fail_closed_rate_limit_enforcement is on. Docs | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Id |
object | string | Yes | Object |
created | integer | Yes | Created |
model | string or null | Yes | Model |
choices | array of object | Yes | Choices |
usage | object or null | Yes |
POST /v1/completions
Create a text completion
Continue a plain text prompt, in the legacy OpenAI completions format, for older clients and instruct models. New integrations should use chat completions. Any virtual key that may use the named model can call it. The gateway checks the key's budget, rate limits and guardrails first, sends the request to one of the model group's deployments with retries and fallbacks, and records the cost and usage in the spend logs. Nothing else changes.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
model | query | string or null | No | |
x-spanway-routing-skips | header | enum: "true" | No | Send true to get the candidates the router skipped in the answer headers. See https://docs.spanway.ai/docs/proxy/routing_headers |
Request body (application/json, object):
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model |
prompt | string or array of string | Yes | Prompt |
max_tokens | integer or null | No | Max Tokens |
temperature | number or null | No | Temperature |
top_p | number or null | No | Top P |
n | integer or null | No | N |
stream | boolean or null | No | Stream |
stop | string or array of string or null | No | Stop |
logprobs | integer or null | No | Logprobs |
echo | boolean or null | No | Echo |
suffix | string or null | No | Suffix |
presence_penalty | number or null | No | Presence Penalty |
frequency_penalty | number or null | No | Frequency Penalty |
best_of | integer or null | No | Best Of |
logit_bias | object or null | No | Logit Bias |
user | string or null | No | User |
Example request:
curl -X POST "http://localhost:4000/v1/completions" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-3.5-turbo-instruct",
"prompt": "def fibonacci(n):",
"max_tokens": 120,
"temperature": 0
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The completion in the OpenAI text completion shape. | application/json object |
| 400 | The request is invalid, for example a missing or unsupported parameter, a prompt longer than the model's context window, content a guardrail or the provider refused, or no deployment that satisfies the data policy of the key, team or organization (No deployment of model 'gpt-5.5' satisfies the data policy: ...). error.message says which. | application/json ProxyError |
| 401 | No valid key was sent, or the key has expired or is blocked. | application/json ProxyError |
| 403 | The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403. | application/json ProxyError |
| 404 | The route or resource does not exist, or this key cannot see it. An unknown model name is a 400 (Invalid model name passed in model=...). | application/json ProxyError |
| 408 | The provider did not answer before the request timed out. | application/json ProxyError |
| 413 | The request body is larger than max_request_size_mb (100 MB by default), or an upload is larger than its own limit. The gateway refused it before reading the key. Docs | application/json object |
| 422 | The request body does not have the expected shape, or a budget (key, user, team, organization or end user) is used up: error.type is budget_exceeded. The budget status is spanway_settings.budget_exceeded_status_code, 422 by default. With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError or HTTPValidationError |
| 429 | Too many requests. A provider limit or a gateway limit (requests or tokens per minute, or parallel requests) refused the call, and error.type says which. A gateway limit also sends the RateLimit headers and x-spanway-rate-limited-by. Docs With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError |
| 500 | The gateway or the provider failed unexpectedly, or the gateway could not reach the provider. Retry, and quote the request id if it keeps failing. | application/json ProxyError |
| 502 | The provider, or a proxy in front of it, answered with something that is not a valid response. | application/json ProxyError |
| 503 | The provider is overloaded or unavailable. With Redis rate limiting, a 503 also means the gateway could not check the rate limit counters and refused the request, because fail_closed_rate_limit_enforcement is on. Docs | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Id |
object | string | Yes | Object |
created | integer | Yes | Created |
model | string or null | Yes | Model |
choices | array of object | Yes | Choices |
usage | object or null | Yes |