Ostra Pro with OpenAI and Anthropic clients
Use Ostra Pro from the OpenAI and Anthropic SDKs, LangChain, the Vercel AI SDK and any tool with an OpenAI-compatible base URL — base URLs, keys, sessions, streaming and cold starts.
Ostra Pro speaks two API formats, so most LLM tooling works by changing three settings:
| Setting | OpenAI-compatible clients | Anthropic clients |
|---|---|---|
| Base URL | https://ostra.testrelic.ai/api/v1 | https://ostra.testrelic.ai/api |
| API key | Your Ostra key (ostk_live_…) | Your Ostra key |
| Model | ostra-pro | ostra-pro (any value is accepted) |
Every example reads the key from OSTRA_API_KEY.
OpenAI SDK
import os
from openai import OpenAI
client = OpenAI(
base_url="https://ostra.testrelic.ai/api/v1",
api_key=os.environ["OSTRA_API_KEY"],
default_headers={"x-ostra-session": "checkout-debugging"}, # one value per conversation
max_retries=6, # rides out a cold start on non-streaming calls
)
completion = client.chat.completions.create(
model="ostra-pro",
reasoning_effort="medium",
messages=[
{"role": "system", "content": "You are a senior test engineer."},
{"role": "user", "content": "Why would page.waitForURL time out only on CI?"},
],
)
print(completion.choices[0].message.content)To turn thinking off for a quick, cheap answer, pass extra_body={"chat_template_kwargs": {"enable_thinking": False}} in Python, or add chat_template_kwargs: { enable_thinking: false } to the request body in TypeScript.
Anthropic SDK
import os
import anthropic
client = anthropic.Anthropic(
base_url="https://ostra.testrelic.ai/api",
api_key=os.environ["OSTRA_API_KEY"],
default_headers={"x-ostra-session": "checkout-debugging"},
)
message = client.messages.create(
model="ostra-pro",
max_tokens=2048,
messages=[{"role": "user", "content": "Write a Playwright test that the cart badge shows 3 items."}],
)
# A thinking block can come before the answer: print the text blocks.
print("".join(block.text for block in message.content if block.type == "text"))Anthropic-format differences: output_config.effort above medium runs as medium; tool_choice any or tool runs as auto; count_tokens isn't supported. See Create a message.
LangChain
import os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="ostra-pro",
base_url="https://ostra.testrelic.ai/api/v1",
api_key=os.environ["OSTRA_API_KEY"],
)
print(llm.invoke("List edge cases for a coupon code input field.").content)Vercel AI SDK
Use the OpenAI-compatible provider, which calls Chat Completions:
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
import { generateText } from 'ai';
const ostra = createOpenAICompatible({
name: 'ostra',
baseURL: 'https://ostra.testrelic.ai/api/v1',
apiKey: process.env.OSTRA_API_KEY,
});
const { text } = await generateText({
model: ostra('ostra-pro'),
prompt: 'Turn this bug report into test cases: "Coupon accepted after expiry date".',
});
console.log(text);Other tools
Any tool that lets you set an OpenAI-compatible base URL (sometimes called "custom OpenAI endpoint" or "OpenAI-compatible provider") works the same way: base URL https://ostra.testrelic.ai/api/v1, your Ostra key as the API key, model ostra-pro. Tools that only speak the newer OpenAI Responses API won't work: Ostra Pro serves Chat Completions.
Claude Code
Claude Code can run on Ostra Pro through the Anthropic-compatible endpoint:
export ANTHROPIC_BASE_URL="https://ostra.testrelic.ai/api"
export ANTHROPIC_AUTH_TOKEN="$OSTRA_API_KEY"
export ANTHROPIC_MODEL="ostra-pro"
claudeSupported through the Anthropic-compatible endpoint
Claude Code talks to Ostra Pro through /api/v1/messages, with the adaptations listed above. If a Claude Code feature doesn't work as expected, contact TestRelic support with the request id from Logs.
Good practice
- One session per conversation. Send
x-ostra-sessionwith a stable value per conversation or agent run, so follow-up turns usually stay on one replica and more of them bill as cached input. See Sessions and caching. - Stream, or allow retries. The first request after 5 quiet minutes starts the model. Streaming waits for it; non-streaming calls may get
503withRetry-After, which SDK retries absorb if you allow enough of them. See Cold starts. - Warm up before bursts.
POST /api/v1/warmis free. - Size
max_tokens. The most a request can cost is held from your balance before it runs; a smallermax_tokensmeans a smaller hold. - Use a dedicated key with a monthly spend cap for each tool.
Related
Coding agents
Connect Claude Code, Cursor or VS Code to the Ostra MCP server, then teach your agent when to triage a failure, pick impacted tests, check selectors and ask Ostra Pro — with ready-made CLAUDE.md and Cursor rules.
Troubleshooting
Fixes for every common Ostra error — authentication, permissions, balance and spend limits, rate limits, cold starts, broken streams, MCP connection problems, empty answers, defer answers and cache surprises — plus an FAQ.