/v1/chat/completions, allowing you to use the OpenAI SDK and libraries to interact with your configured language models.
Endpoint
Authentication
Include your Spice API key in the request headers:Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | The name of the language model to use (e.g., gpt-4o, gpt-4o-mini) |
messages | array | Yes | Array of message objects with role and content |
stream | boolean | No | Whether to stream the response (default: false) |
temperature | number | No | Sampling temperature between 0 and 2 |
max_tokens | integer | No | Maximum number of tokens to generate |
top_p | number | No | Nucleus sampling parameter |
frequency_penalty | number | No | Penalty for token frequency |
presence_penalty | number | No | Penalty for token presence |
Message Roles
system- System instructions for the modeluser- User messagesassistant- Assistant responsesdeveloper- Developer-level instructions (supported by some models)
Response Format
Non-Streaming Response
Streaming Response
Whenstream: true, the response is sent as Server-Sent Events (SSE):
Advanced: Completion Progress Tracking
Spice supports tracking completion progress through an optional header:Examples
cURL
OpenAI Python SDK
Streaming Example (Python)
OpenAI Node.js SDK
Streaming Example (Node.js)
Error Responses
Model Not Found (404)
API Error (4xx/5xx)
400- Invalid request parameters401- Invalid API key402- Insufficient quota404- Model not found429- Rate limit exceeded500- Internal server error
Supported Models
The available models depend on your Spice configuration. Common models include:- OpenAI models:
gpt-4o,gpt-4o-mini,gpt-4-turbo,gpt-3.5-turbo - Anthropic models:
claude-3-5-sonnet,claude-3-opus,claude-3-haiku - Open-source models: Configure custom models in your Spicepod