SDK and code examples

Stravia provides OpenAI-compatible, Anthropic Messages, and Google Gemini APIs. Use your preferred SDK or language with the appropriate endpoint and Stravia API Key.

Supported protocols and SDKs

OpenAI-compatible

Works with OpenAI SDK, Vercel AI SDK, and any client expecting OpenAI Chat Completions format.

from openai import OpenAI

client = OpenAI(
    base_url="http://127.0.0.1:23471/v1",
    api_key="<your-stravia-api-key>"
)

response = client.chat.completions.create(
    model="my-model",
    messages=[{"role": "user", "content": "Hello"}]
)
print(response.choices[0].message.content)
python

Anthropic Messages

Use the Anthropic SDK to request Claude models through Stravia.

from anthropic import Anthropic

client = Anthropic(
    base_url="http://127.0.0.1:23471",
    api_key="<your-stravia-api-key>"
)

response = client.messages.create(
    model="my-model",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}]
)
print(response.content[0].text)
python

Google Gemini

Use the Google Generative AI SDK to request Gemini models through Stravia.

from google import genai

client = genai.Client(
    api_key="<your-stravia-api-key>",
    http_options={"base_url": "http://127.0.0.1:23471"}
)

response = client.models.generate_content(
    model="my-model",
    contents="Hello"
)
print(response.text)
python

Install the SDK with:

pip install google-genai
sh

cURL examples

OpenAI-compatible

curl http://127.0.0.1:23471/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <your-api-key>" \
  -d '{
    "model": "my-model",
    "messages": [{"role": "user", "content": "Hello"}]
  }'
sh

Anthropic Messages

curl http://127.0.0.1:23471/v1/messages \
  -H "Content-Type: application/json" \
  -H "x-api-key: <your-api-key>" \
  -d '{
    "model": "my-model",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Hello"}]
  }'
sh

Check the request

After making a request, open Request history in Stravia to confirm it arrived, see the model response, and view any errors or telemetry.

Common issues

  • Authorization failed: Verify your API Key is enabled and authorized for the requested model.
  • Model not found: Ensure the model ID matches exactly what you configured in Models.
  • Connection refused: Check that Stravia Server is running and listening on the configured address.

Next steps

For a general overview see Connect clients . For request troubleshooting see Model request failed .