HomeResources
04DOCUMENTATION & SUPPORT

Docs & support

From your first line of code to your next product.

Getting started / API5 languages · standard & streamingJump to code

Quick start

Set up an API key, choose a model and check your quota before sending your first request.

Model calls use Relay API keys. Dashboard access tokens and PATs cannot replace them.

Environment setup

Store your API key in a server environment variable and configure your SDK with the Base URL below.

BASE URLhttps://keda8.ai/v1
AUTHORIZATIONBearer $AI_API_KEY
CONTENT-TYPEapplication/json
Terminal
export AI_API_KEY="YOUR_RELAY_API_KEY"
export AI_BASE_URL='https://keda8.ai/v1'

Replace YOUR_RELAY_API_KEY with your own key. These variables apply to the current terminal session; run subsequent code in the same terminal. Do not append /v1 twice.

Code examples

Choose a language and copy a complete example. Standard requests return the full result; streaming requests deliver output as it arrives.

POST /chat/completions
request.sh
curl --fail-with-body "https://keda8.ai/v1/chat/completions" \
  --connect-timeout 10 --max-time 60 \
  -H "Authorization: Bearer $AI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "YOUR_CONFIGURED_MODEL_ID",
  "messages": [
    {
      "role": "user",
      "content": "Hello!"
    }
  ],
  "stream": false
}'
cURL 7.76+. On Windows, run this example in WSL or Git Bash.
Install & run
bash request.sh

This example prints raw JSON or SSE events. The Python and JavaScript SDK examples extract the reply text.

Replace YOUR_CONFIGURED_MODEL_ID with an exact model ID from Models & Pricing. These examples require explicit Chat Completions support. Check model documentation for other capabilities.

Understanding responses

The following examples illustrate the response structure. Fields and token counts are illustrative, not results from an actual request.

response.json
{
  "id": "chatcmpl-example",
  "object": "chat.completion",
  "model": "YOUR_CONFIGURED_MODEL_ID",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello!"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 9,
    "completion_tokens": 2,
    "total_tokens": 11
  }
}

choices[0].message.contentRead the complete reply text.

finish_reasonCheck why generation ended, such as stop or length. A length-limited response may need continuation.

usageReview input, output and total tokens. Request logs determine actual billing.

Endpoints & parameters

Paths below are relative to the Base URL. Availability depends on model capabilities, API key permissions and backend configuration.

POST/chat/completions
Chat completions

The endpoint used in these examples, for models that explicitly support Chat Completions.

GET/models
Available models

List models accessible with your Relay API Key. Find pricing on Models & Pricing.

POST/embeddings
Embeddings

For models supporting Embeddings. Provide the corresponding model ID and input.

POST/images/generations
Image generation

For image generation models. Parameters and billing depend on the model.

Chat Completions request parameters

ParameterType / requirementDescription
modelstringRequiredThe exact model ID from Models & Pricing. Your API key must have access to it.
messagesarrayRequiredAn ordered list of conversation messages, each with a role and content.
streambooleanOptionalSet to true for SSE events. Standard requests return a complete JSON response.
temperaturenumberModel dependentControls sampling randomness. Supported values depend on the model.
max_completion_tokensintegerModel dependentLimits generated tokens. Some models use max_tokens; follow the model's documentation.

Tool calls, structured output, image input and other parameters are not universal. Start with a minimal request, then add parameters confirmed to be supported.

Troubleshooting

Read the HTTP status and error body, then check the relevant configuration. Upstream services may map errors differently; use the actual message to diagnose the issue.

400
Invalid request format

Check your JSON, required fields, context length and whether the model supports your parameters.

401
API key authentication failed

Use a valid Relay API Key and check for extra whitespace after Authorization: Bearer.

402 / 403
Balance or permission restriction

Read the error body and check your balance, key quota, group, model permissions and IP restrictions.

404
Endpoint or model not found

Check that your Base URL contains /v1 only once, and verify the exact model ID and endpoint.

429
Rate limit or quota exceeded

Read the error body to distinguish rate limits from quota limits. Reduce concurrency and honor Retry-After when applicable.

5xx
Gateway or upstream error

Save the error body and request ID, then check your logs. Use bounded backoff only after confirming a retry is appropriate.

TIMEOUT
Connection timeout or interrupted stream

Check your network, proxy buffering and client timeout. A partial response should not be treated as a complete answer.

A network error does not necessarily mean a request was not processed. After a timeout or interrupted stream, check your logs before resubmitting.

Common questions

Troubleshooting & support

Having trouble with a request? Start with your API key, model configuration and request logs.

Make the issue reproducible

Record the time, model ID, endpoint, SDK version and full error details. Remove API keys and sensitive content before sharing.