Python
Working examples with the anthropic and openai packages, including streaming and async.
Anthropic SDK
pip install anthropic
import os
from anthropic import Anthropic
client = Anthropic(
api_key=os.environ[class="s">"CLAUDEAPIKEY"],
base_url=class="s">"https://aiprimetech.io", class=class="s">"c"># no /v1
)
msg = client.messages.create(
model=class="s">"claude-sonnet-4-6",
max_tokens=1024,
system=class="s">"You are a concise assistant.",
messages=[{class="s">"role": class="s">"user", class="s">"content": class="s">"Explain HTTP caching in three sentences."}],
)
print(msg.content[0].text)
print(msg.usage.input_tokens, msg.usage.output_tokens)
Streaming
with client.messages.stream(
model=class="s">"claude-sonnet-4-6",
max_tokens=1024,
messages=[{class="s">"role": class="s">"user", class="s">"content": class="s">"Write a haiku about latency."}],
) as stream:
for text in stream.text_stream:
print(text, end=class="s">"", flush=True)
final = stream.get_final_message()
print(class="s">"\n", final.usage.output_tokens, class="s">"output tokens")
Async
import asyncio
from anthropic import AsyncAnthropic
client = AsyncAnthropic(api_key=class="s">"sk-your-key", base_url=class="s">"https://aiprimetech.io")
async def ask(q):
m = await client.messages.create(
model=class="s">"claude-haiku-4-5", max_tokens=256,
messages=[{class="s">"role": class="s">"user", class="s">"content": q}],
)
return m.content[0].text
async def main():
sem = asyncio.Semaphore(8) class=class="s">"c"># respect rate limits
async def guarded(q):
async with sem:
return await ask(q)
print(await asyncio.gather(*(guarded(q) for q in [class="s">"1+1?", class="s">"2+2?", class="s">"3+3?"])))
asyncio.run(main())
OpenAI SDK
from openai import OpenAI
client = OpenAI(api_key=class="s">"sk-your-key", base_url=class="s">"https://aiprimetech.io/v1") class=class="s">"c"># with /v1
resp = client.chat.completions.create(
model=class="s">"claude-sonnet-4-6",
messages=[{class="s">"role": class="s">"user", class="s">"content": class="s">"Hello"}],
)
print(resp.choices[0].message.content)
Both snippets call the same model at the same price. Use whichever library your project already depends on.