Send chat messages and stream responses using the OpenDunes API from Go.
Chat completions are the core of the OpenDunes API. Send a messages array, get a response — or stream tokens as they arrive.
The endpoint follows the OpenAI chat-completions schema, so an OpenAI-compatible Go client pointed at https://opendunes.com/v1 drives it through its chat service — check your installed SDK version's own documentation for the exact call shape, since the Go client's parameter helpers change between releases. The wire surface below is the contract any Go HTTP client can target directly.
POST /chat/completions with a model and a messages array:
curl https://opendunes.com/v1/chat/completions \
-H "Authorization: Bearer $OPENDUNES_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "google/gemini-2.5-pro",
"messages": [
{ "role": "system", "content": "You are a helpful assistant." },
{ "role": "user", "content": "What is the capital of Algeria?" }
],
"max_tokens": 512,
"temperature": 0.7
}'The response carries the reply in choices[0].message.content and token counts in usage:
{
"choices": [{ "message": { "role": "assistant", "content": "Algiers." } }],
"usage": { "prompt_tokens": 18, "completion_tokens": 3 }
}Set "stream": true and the server emits SSE data: chunks, each carrying a choices[0].delta.content fragment, terminated by a data: [DONE] sentinel. The final chunk carries token usage in usage.
curl https://opendunes.com/v1/chat/completions \
-H "Authorization: Bearer $OPENDUNES_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "anthropic/claude-opus-4.8",
"messages": [
{ "role": "user", "content": "Explain gradient descent in two sentences." }
],
"stream": true
}'An OpenAI-compatible Go client exposes this through its streaming call (the equivalent of Chat.Completions.NewStreaming), iterating chunks until the stream closes.
| Parameter | Type | Notes |
|---|---|---|
model | string | Required. provider/model slug — see Models. |
messages | array | Required. Roles: system, user, assistant. |
stream | bool | Stream SSE delta chunks. |
max_tokens | int | Cap output length. |
temperature | float (0–2) | Sampling temperature. |
top_p | float (0–1) | Nucleus sampling. |
Each response includes:
X-Request-Id — UUID-v7 trace ID (quote this in support requests).X-Balance-Available — remaining balance in micro-DA, after this request's charge. Not on a streamed answer.There is no cap on the number of requests, so there is no request counter.
On failure the API returns a JSON body { "error": { "code": <status>, "message": "<text>", "metadata": { "error_type": "<word>" } } }. Common cases: 402 payment_required (top up your DA balance, or raise the key's cap — metadata.limit_source says which), 429 rate_limit_exceeded (the provider's — respect the Retry-After header), 404 not_found (the model is not on sale). See Errors.