Get started

SDKs & frameworks

Use Straitly with your existing SDK or framework. Choose an integration below, set your API key, and send your first request. Available features depend on the model you select.

Before you start

Create an API key and ensure your account has credits. Use Python 3.10+ for Python examples or Node.js 22+ for TypeScript. Install the packages in your project environment and run the code on your server or in a terminal.

Set your key in the same terminal before running an example (macOS / Linux):

Terminal
export STRAITLY_API_KEY="YOUR_STRAITLY_API_KEY"
Windows PowerShell
PowerShell
$env:STRAITLY_API_KEY="YOUR_STRAITLY_API_KEY"

These examples use claude-sonnet-5. Choose another supported ID from the models page. Keep keys out of browser bundles and source control.

OpenAI SDK

Use Chat Completions for a direct request without a framework. The same client can call different models by changing the model ID.

Use chat.completions.create with the /v1 base URL. These examples target Chat Completions, not the SDK's Responses API.

Install

Terminal
python -m pip install openai

Send a message

example.py / python
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.straitly.ai/v1",
    api_key=os.environ["STRAITLY_API_KEY"],
)

response = client.chat.completions.create(
    model="claude-sonnet-5",
    messages=[{"role": "user", "content": "Say hello in one sentence."}],
)
print(response.choices[0].message.content)

Run

Terminal
python example.py

The script prints the model’s reply to your terminal.

OpenAI SDK reference

Anthropic SDK

Keep the Messages API format in an application that uses the Anthropic SDK. Read text from the response's content blocks.

Omit /v1 from this SDK's base URL: it adds /v1/messages itself. max_tokens is required. Filter text blocks because a response may also contain tool-use or other blocks.

Install

Terminal
python -m pip install anthropic

Send a message

example.py / python
import os
from anthropic import Anthropic

client = Anthropic(
    base_url="https://api.straitly.ai",
    api_key=os.environ["STRAITLY_API_KEY"],
)

response = client.messages.create(
    model="claude-sonnet-5",
    max_tokens=256,
    messages=[{"role": "user", "content": "Say hello in one sentence."}],
)
for block in response.content:
    if block.type == "text":
        print(block.text)

Run

Terminal
python example.py

The script prints the model’s reply to your terminal.

Anthropic SDK reference

LangChain

Connect a chat model to an existing LangChain application. Start with a single invocation before adding chains or tools.

use_responses_api=False keeps this example on Chat Completions. Provider-specific extras and hosted tools are not implied by OpenAI compatibility.

Install

Terminal
python -m pip install langchain-openai

Send a message

example.py / python
import os
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="claude-sonnet-5",
    base_url="https://api.straitly.ai/v1",
    api_key=os.environ["STRAITLY_API_KEY"],
    use_responses_api=False,
)

response = llm.invoke([("human", "Say hello in one sentence.")])
print(response.content)

Run

Terminal
python example.py

The script prints the model’s reply to your terminal.

LangChain reference

LlamaIndex

Use OpenAILike to connect a third-party model to LlamaIndex. This example sends a chat message; it does not configure embeddings or a retrieval index.

Set is_chat_model=True to use Chat Completions. For retrieval workloads, set context_window to the selected model's documented context size. Only enable is_function_calling_model for models that support tools.

Install

Terminal
python -m pip install llama-index-llms-openai-like

Send a message

example.py / python
import os
from llama_index.core.llms import ChatMessage
from llama_index.llms.openai_like import OpenAILike

llm = OpenAILike(
    model="claude-sonnet-5",
    api_base="https://api.straitly.ai/v1",
    api_key=os.environ["STRAITLY_API_KEY"],
    is_chat_model=True,
    max_tokens=256,
)

response = llm.chat([
    ChatMessage(role="user", content="Say hello in one sentence.")
])
print(response.message.content)

Run

Terminal
python example.py

The script prints the model’s reply to your terminal.

LlamaIndex reference

Vercel AI SDK

Use generateText in a server-side TypeScript application. Create a custom provider and explicitly select its Chat Completions model.

Use straitly.chat(modelId), not straitly(modelId). The default OpenAI provider factory uses Responses in AI SDK 5 and later. Keep this code on the server so the key is never shipped to a browser.

Install

Terminal
npm install ai @ai-sdk/openai
npm install --save-dev tsx typescript @types/node

Send a message

example.ts / typescript
import { createOpenAI } from "@ai-sdk/openai";
import { generateText } from "ai";

async function main() {
  const straitly = createOpenAI({
    baseURL: "https://api.straitly.ai/v1",
    apiKey: process.env.STRAITLY_API_KEY!,
  });

  const { text } = await generateText({
    model: straitly.chat("claude-sonnet-5"),
    prompt: "Say hello in one sentence.",
  });
  console.log(text);
}

main().catch(console.error);

Run

Terminal
npx tsx example.ts

The script prints the model’s reply to your terminal.

Vercel AI SDK reference

Troubleshooting

  • 401: confirm STRAITLY_API_KEY is set in the same terminal or server process that runs your code.
  • 402: check your prepaid balance and the key's spending cap.
  • 404: check the base URL, endpoint, and model ID. Use /v1 for OpenAI-compatible clients; omit it for the Anthropic SDK.
  • Tools, vision, and structured outputs depend on model capabilities. A compatible SDK does not make every model support every feature.

Next: stream a response or check Errors & limits for the full error reference.