V1ChatCompletions
Create chat completion
Chat Completions API
Generate AI chat completions using various models with support for multiple payment methods.
Payment Methods
1. Credit-Based Payments (Traditional)
Pre-fund your account and pay per request. Costs are deducted from your balance automatically.
- Simple Setup: Add funds to your account
- Instant Processing: No additional payment verification needed
- Predictable Billing: Pre-pay for usage
2. x402 Cryptocurrency Payments (Revolutionary)
Pay for requests in real-time using cryptocurrency without pre-funding accounts.
- Supported Assets: USDC
- Networks: Base
- Protocol: x402 standard for AI micropayments
- Benefits: No account funding, transparent pricing, crypto-native experience
Streaming Support
Enable real-time streaming by setting "stream": true
. Responses are delivered
as Server-Sent Events (SSE).
Streaming Features:
- Real-time token generation
- Lower perceived latency
- Progressive response display
- Automatic cost settlement after completion
Cost Calculation
Costs are calculated based on:
- Input Tokens: Text you send to the model
- Output Tokens: Text generated by the model
- Model Pricing: Different models have different rates
Error Handling
The API handles various error scenarios:
- 402 Payment Required: Insufficient balance or invalid x402 payment
- 429 Rate Limited: Too many requests
- 400 Bad Request: Invalid request parameters
- 500 Server Error: Internal processing errors
AuthorizationBearer <token>
Enter your JWT token in the format: Bearer
In: header
modelstring
Length
1 <= length
models?array<string>
messagesarray<object>
max_tokens?number
temperature?number
stream?boolean
modelCriteria?string
Value in
"cheapest" | "fastest" | "balanced"
x402Payment?string
tools?array<object>
tool_choice?string & object
parallel_tool_calls?boolean
top_p?number
frequency_penalty?number
presence_penalty?number
stop?string & array<string>
seed?number
response_format?unknown
logprobs?boolean
top_logprobs?number
user?string
Response Body
curl -X POST "https://api-beta.daydreams.systems/v1/chat/completions" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-4",
"messages": [
{
"role": "user",
"content": "Hello, how are you?"
}
],
"max_tokens": 150,
"temperature": 0.7
}'
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1699896901,
"model": "openai/gpt-4",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! I'm doing well, thank you for asking. How can I help you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 19,
"total_tokens": 31,
"cost_usd": 0.000031,
"platform_fee_usd": 0.0000047,
"payment_method": "credits"
}
}
{
"error": "Invalid model specified",
"code": "INVALID_MODEL",
"message": "The specified model is not available"
}
{
"error": "Invalid API key",
"code": "INVALID_API_KEY",
"message": "The provided API key is not valid"
}
{
"error": "Insufficient balance",
"code": "INSUFFICIENT_BALANCE",
"message": "Account balance is too low for this operation",
"current_balance": 1.25,
"required_amount": 5
}
{
"error": "Rate limit exceeded",
"code": "RATE_LIMIT_EXCEEDED",
"message": "Too many requests. Please try again later.",
"retry_after": 60
}
{
"error": "Internal server error",
"code": "INTERNAL_SERVER_ERROR",
"message": "An unexpected error occurred while processing your request"
}