---
title: "SDKs: OpenAI, Anthropic, AI SDK & LangChain | Straitly Docs"
description: "Drop-in setup snippets for the OpenAI SDK, Anthropic SDK, Vercel AI SDK, LangChain and LiteLLM by changing one base URL and API key."
url: https://straitly.ai/docs/sdks
updated: 2026-11-25
publisher: Straitly (https://straitly.ai)
---

Docs

Get started

# SDKs & frameworks

Copy docs

**On this page**

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](https://straitly.ai/app/keys) 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

Copy Copied Failed

export STRAITLY_API_KEY="YOUR_STRAITLY_API_KEY"

**Windows PowerShell**

PowerShell

Copy Copied Failed

$env:STRAITLY_API_KEY="YOUR_STRAITLY_API_KEY"

These examples use `claude-sonnet-5-5`. Choose another supported ID from the [models page](https://straitly.ai/models). 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.

Python TypeScript

#### Install

Terminal

Copy Copied Failed

python -m pip install openai

#### Send a message

example.py / python

Copy Copied Failed

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-5",
    messages=[{"role": "user", "content": "Say hello in one sentence."}],
)
print(response.choices[0].message.content)

#### Run

Terminal

Copy Copied Failed

python example.py

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

[OpenAI SDK reference](https://developers.openai.com/api/reference/resources/chat/subresources/completions/methods/create)

### 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.

Python TypeScript

#### Install

Terminal

Copy Copied Failed

python -m pip install anthropic

#### Send a message

example.py / python

Copy Copied Failed

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-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

Copy Copied Failed

python example.py

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

[Anthropic SDK reference](https://platform.claude.com/docs/en/api/client-sdks)

### 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

Copy Copied Failed

python -m pip install langchain-openai

#### Send a message

example.py / python

Copy Copied Failed

import os
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="claude-sonnet-5-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

Copy Copied Failed

python example.py

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

[LangChain reference](https://docs.langchain.com/oss/python/integrations/chat/openai)

### 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

Copy Copied Failed

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

#### Send a message

example.py / python

Copy Copied Failed

import os
from llama_index.core.llms import ChatMessage
from llama_index.llms.openai_like import OpenAILike

llm = OpenAILike(
    model="claude-sonnet-5-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

Copy Copied Failed

python example.py

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

[LlamaIndex reference](https://developers.llamaindex.ai/python/framework-api-reference/llms/openai%5Flike/)

### 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

Copy Copied Failed

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

#### Send a message

example.ts / typescript

Copy Copied Failed

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-5"),
    prompt: "Say hello in one sentence.",
  });
  console.log(text);
}

main().catch(console.error);

#### Run

Terminal

Copy Copied Failed

npx tsx example.ts

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

[Vercel AI SDK reference](https://ai-sdk.dev/providers/ai-sdk-providers/openai)

### 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](https://straitly.ai/docs/streaming) or check [Errors & limits](https://straitly.ai/docs/errors) for the full error reference.

[Endpoints](https://straitly.ai/docs/endpoints) [Connect Cursor](https://straitly.ai/docs/cursor)

---
Markdown version of https://straitly.ai/docs/sdks.
