# Python > Working examples with the anthropic and openai packages, including streaming and async. _Source: https://aiprimetech.io/docs/sdks/python/ ยท Home > Docs > SDKs_ ## Anthropic SDK ```bash pip install anthropic ``` ```python import os from anthropic import Anthropic client = Anthropic( api_key=os.environ["CLAUDEAPIKEY"], base_url="https://aiprimetech.io", # no /v1 ) msg = client.messages.create( model="claude-sonnet-4-6", max_tokens=1024, system="You are a concise assistant.", messages=[{"role": "user", "content": "Explain HTTP caching in three sentences."}], ) print(msg.content[0].text) print(msg.usage.input_tokens, msg.usage.output_tokens) ``` ## Streaming ```python with client.messages.stream( model="claude-sonnet-4-6", max_tokens=1024, messages=[{"role": "user", "content": "Write a haiku about latency."}], ) as stream: for text in stream.text_stream: print(text, end="", flush=True) final = stream.get_final_message() print("\n", final.usage.output_tokens, "output tokens") ``` ## Async ```python import asyncio from anthropic import AsyncAnthropic client = AsyncAnthropic(api_key="sk-your-key", base_url="https://aiprimetech.io") async def ask(q): m = await client.messages.create( model="claude-haiku-4-5", max_tokens=256, messages=[{"role": "user", "content": q}], ) return m.content[0].text async def main(): sem = asyncio.Semaphore(8) # respect rate limits async def guarded(q): async with sem: return await ask(q) print(await asyncio.gather(*(guarded(q) for q in ["1+1?", "2+2?", "3+3?"]))) asyncio.run(main()) ``` ## OpenAI SDK ```python from openai import OpenAI client = OpenAI(api_key="sk-your-key", base_url="https://aiprimetech.io/v1") # with /v1 resp = client.chat.completions.create( model="claude-sonnet-4-6", messages=[{"role": "user", "content": "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. - [Messages API](https://aiprimetech.io/docs/api-reference/messages/) โ€” Field reference - [Streaming](https://aiprimetech.io/docs/api-reference/streaming/) โ€” Event shapes - [Best practices](https://aiprimetech.io/docs/guides/best-practices/) โ€” Timeouts and retries --- _ClaudeAPIKey.dev is an independently operated, Anthropic-compatible API gateway. Not affiliated with Anthropic._