SDKs
Any OpenAI or Anthropic SDK works out of the box.
Shannon speaks the OpenAI and the Anthropic wire formats, so you use the official SDKs of both as they are. You change three values in the client: the base URL, the API key and the model id. The rest of your code stays the same.
What to set
| Setting | OpenAI SDKs | Anthropic SDKs |
|---|---|---|
| Base URL | https://api.shannon-ai.com/v1 | https://api.shannon-ai.com |
| API key | Your Shannon key. The SDK sends it as Authorization: Bearer. | Your Shannon key. The SDK sends it as x-api-key. |
| Model | A published model id, for example shannon-3. | A published model id, for example shannon-1.6-lite. |
| Endpoints it reaches | /v1/chat/completions, /v1/responses, /v1/models | /v1/messages, /v1/messages/count_tokens |
| Environment variables | OPENAI_API_KEY and OPENAI_BASE_URL, read by the Python and JavaScript SDKs when you pass no value. | ANTHROPIC_API_KEY and ANTHROPIC_BASE_URL, read by the Python and TypeScript SDKs when you pass no value. |
The two base URLs differ by /v1: an OpenAI SDK adds /chat/completions to its base URL, an Anthropic SDK adds /v1/messages. A model name that Shannon does not publish is answered with 400 and unknown model. Models & pricing
Your key is on the Keys & usage page. Keys & usage
OpenAI SDKs
The official OpenAI SDKs call POST /v1/chat/completions and POST /v1/responses. Each sample sends one user message and prints the answer.
# pip install openai
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.shannon-ai.com/v1",
)
response = client.chat.completions.create(
model="shannon-3",
messages=[{"role": "user", "content": "Hello, Shannon!"}],
)
print(response.choices[0].message.content) // npm install openai
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "YOUR_API_KEY",
baseURL: "https://api.shannon-ai.com/v1",
});
const response = await client.chat.completions.create({
model: "shannon-3",
messages: [{ role: "user", content: "Hello, Shannon!" }],
});
console.log(response.choices[0].message.content); // go get github.com/openai/openai-go/v3
package main
import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
"github.com/openai/openai-go/v3/option"
)
func main() {
client := openai.NewClient(
option.WithAPIKey("YOUR_API_KEY"),
option.WithBaseURL("https://api.shannon-ai.com/v1/"),
)
completion, err := client.Chat.Completions.New(context.TODO(), openai.ChatCompletionNewParams{
Model: "shannon-3",
Messages: []openai.ChatCompletionMessageParamUnion{
openai.UserMessage("Hello, Shannon!"),
},
})
if err != nil {
panic(err)
}
fmt.Println(completion.Choices[0].Message.Content)
} // Gradle: implementation("com.openai:openai-java:<version>")
import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.chat.completions.ChatCompletion;
import com.openai.models.chat.completions.ChatCompletionCreateParams;
OpenAIClient client = OpenAIOkHttpClient.builder()
.apiKey("YOUR_API_KEY")
.baseUrl("https://api.shannon-ai.com/v1")
.build();
ChatCompletionCreateParams params = ChatCompletionCreateParams.builder()
.model("shannon-3")
.addUserMessage("Hello, Shannon!")
.build();
ChatCompletion completion = client.chat().completions().create(params);
completion.choices().get(0).message().content().ifPresent(System.out::println); // dotnet add package OpenAI
using System.ClientModel;
using OpenAI;
using OpenAI.Chat;
ChatClient client = new(
model: "shannon-3",
credential: new ApiKeyCredential("YOUR_API_KEY"),
options: new OpenAIClientOptions()
{
Endpoint = new Uri("https://api.shannon-ai.com/v1")
});
ChatCompletion completion = client.CompleteChat("Hello, Shannon!");
Console.WriteLine(completion.Content[0].Text); | Language | Install | Base URL option | Source |
|---|---|---|---|
| Python | pip install openai | base_url | openai/openai-python |
| JavaScript / TypeScript | npm install openai | baseURL | openai/openai-node |
| Go | go get github.com/openai/openai-go/v3 | option.WithBaseURL | openai/openai-go |
| Java | com.openai:openai-java | baseUrl | openai/openai-java |
| .NET | dotnet add package OpenAI | OpenAIClientOptions.Endpoint | openai/openai-dotnet |
Every field of the two endpoints is described on their own pages. Chat Completions Responses API
Anthropic SDKs
The official Anthropic SDKs call POST /v1/messages. They require max_tokens on every call, so the samples use shannon-1.6-lite, which applies it. Each sample prints the text blocks of the answer.
# pip install anthropic
import anthropic
client = anthropic.Anthropic(
api_key="YOUR_API_KEY",
base_url="https://api.shannon-ai.com",
)
message = client.messages.create(
model="shannon-1.6-lite",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello, Shannon!"}],
)
for block in message.content:
if block.type == "text":
print(block.text) // npm install @anthropic-ai/sdk
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
apiKey: "YOUR_API_KEY",
baseURL: "https://api.shannon-ai.com",
});
const message = await client.messages.create({
model: "shannon-1.6-lite",
max_tokens: 1024,
messages: [{ role: "user", content: "Hello, Shannon!" }],
});
for (const block of message.content) {
if (block.type === "text") console.log(block.text);
} // go get github.com/anthropics/anthropic-sdk-go
package main
import (
"context"
"fmt"
"github.com/anthropics/anthropic-sdk-go"
"github.com/anthropics/anthropic-sdk-go/option"
)
func main() {
client := anthropic.NewClient(
option.WithAPIKey("YOUR_API_KEY"),
option.WithBaseURL("https://api.shannon-ai.com/"),
)
message, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
Model: "shannon-1.6-lite",
MaxTokens: 1024,
Messages: []anthropic.MessageParam{
anthropic.NewUserMessage(anthropic.NewTextBlock("Hello, Shannon!")),
},
})
if err != nil {
panic(err)
}
for _, block := range message.Content {
if block.Type == "text" {
fmt.Println(block.Text)
}
}
} // Gradle: implementation("com.anthropic:anthropic-java:<version>")
import com.anthropic.client.AnthropicClient;
import com.anthropic.client.okhttp.AnthropicOkHttpClient;
import com.anthropic.models.messages.Message;
import com.anthropic.models.messages.MessageCreateParams;
AnthropicClient client = AnthropicOkHttpClient.builder()
.apiKey("YOUR_API_KEY")
.baseUrl("https://api.shannon-ai.com")
.build();
MessageCreateParams params = MessageCreateParams.builder()
.model("shannon-1.6-lite")
.maxTokens(1024L)
.addUserMessage("Hello, Shannon!")
.build();
Message message = client.messages().create(params);
message.content().stream()
.flatMap(block -> block.text().stream())
.forEach(text -> System.out.println(text.text())); | Language | Install | Base URL option | Source |
|---|---|---|---|
| Python | pip install anthropic | base_url | anthropics/anthropic-sdk-python |
| TypeScript | npm install @anthropic-ai/sdk | baseURL | anthropics/anthropic-sdk-typescript |
| Go | go get github.com/anthropics/anthropic-sdk-go | option.WithBaseURL | anthropics/anthropic-sdk-go |
| Java | com.anthropic:anthropic-java | baseUrl | anthropics/anthropic-sdk-java |
The Messages format and its differences are on the Anthropic compatibility page. Anthropic Format
What the SDKs can rely on
- A request field the API does not use is accepted. A field the API knows, sent with the wrong type, is answered with
422. - The version and beta headers the SDKs add (
anthropic-version,anthropic-beta,openai-beta) are accepted. None of them is required. - The
modelof a reply is the published id, so you can send it back as it is. - On
/v1/messagesa reply can start with athinkingblock. Read the blocks of typetextinstead of taking the first block. - Streaming works through the SDK's own stream helpers. Usage arrives at the end of every stream.
- Every reply carries an
x-request-idheader. Send your ownx-request-idand the same value comes back.
Community SDKs
Clients written for the OpenAI API by other authors work the same way: give the client the base URL with /v1, your key and a Shannon model id. These are maintained by their authors, not by Shannon.
| Language | Install | Client |
|---|---|---|
| Go | go get github.com/sashabaranov/go-openai | sashabaranov/go-openai |
| Ruby | gem install ruby-openai | alexrudall/ruby-openai |
| PHP | composer require openai-php/client | openai-php/client |
| Rust | cargo add async-openai | 64bit/async-openai |
Without an SDK
You do not need an SDK. Any HTTP client that can send JSON works:
POSTwith a JSON body and the headerContent-Type: application/json. Without it the request is answered with415.- Your key in
Authorization: Bearer <key>or inx-api-key: <key>. Both work on every endpoint. - A body of up to 32 MiB.
- With
"stream": truethe reply is a server-sent event stream (text/event-stream). Read it line by line and do not buffer it. - An error is a JSON body with
error.typeanderror.message, next to the HTTP status.
curl https://api.shannon-ai.com/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "shannon-3",
"messages": [{"role": "user", "content": "Hello, Shannon!"}]
}' import requests
response = requests.post(
"https://api.shannon-ai.com/v1/chat/completions",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={
"model": "shannon-3",
"messages": [{"role": "user", "content": "Hello, Shannon!"}],
},
)
response.raise_for_status()
print(response.json()["choices"][0]["message"]["content"]) const response = await fetch("https://api.shannon-ai.com/v1/chat/completions", {
method: "POST",
headers: {
Authorization: "Bearer YOUR_API_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "shannon-3",
messages: [{ role: "user", content: "Hello, Shannon!" }],
}),
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const data = await response.json();
console.log(data.choices[0].message.content); For the events of a stream and the error types, see: Streaming Error Handling