Coco
Look something up

Model providers

Look up the classes and environment variables of coco_openai and coco_anthropic, and how each handles retries, timeouts and rate limits.

Look up coco_openai and coco_anthropic.


coco_openai

From the trustcoco-openai distribution, or the openai extra of coco-framework.

from coco_openai import (
    ChatOpenAI,
    AzureChatOpenAI,
    OpenAI,
    AzureOpenAI,
    OpenAIEmbeddings,
    AzureOpenAIEmbeddings,
    custom_tool,
    StreamChunkTimeoutError,
)

ChatOpenAI supports the Chat Completions API, the Responses API, and any OpenAI-compatible endpoint through base_url.

VariableDescription
OPENAI_API_KEYThe OpenAI API key.
OPENAI_BASE_URL, OPENAI_API_BASEAn OpenAI-compatible endpoint, such as vLLM, Ollama, LiteLLM, or an internal gateway.
OPENAI_ORG_ID, OPENAI_PROJECT_IDOptional organization and project.
AZURE_OPENAI_API_KEY, AZURE_OPENAI_ENDPOINT, OPENAI_API_VERSIONAzure OpenAI credentials.
  • Retries: ChatOpenAI retries HTTP 429 and 5xx errors up to max_retries times, 2 by default, with exponential backoff.
  • Streaming timeouts: A streamed call raises StreamChunkTimeoutError when a chunk is late.
  • Across providers: Combine ModelRetryMiddleware and ModelFallbackMiddleware. See Retries and fallbacks.

Keep in mind: For models whose names start with gpt-6, a call with tools uses the Responses API, so the endpoint must serve /v1/responses.

coco_anthropic

From the trustcoco-anthropic distribution, or the anthropic extra of coco-framework.

from coco_anthropic import (
    ChatAnthropic,
    AnthropicLLM,
    convert_to_anthropic_tool,
)

ChatAnthropic supports Claude models, extended thinking, prompt caching, and native tool use.

VariableDescription
ANTHROPIC_API_KEYThe Anthropic API key.
ANTHROPIC_API_URLAn optional custom endpoint.

See Models for examples.

On this page