Skip to content

API Reference parrot.clients.meta.client

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.clients.meta.client

View source

Meta Model API client for AI-Parrot.

MetaClient subclasses :class:~parrot.clients.openai_base.OpenAIBaseClient — the neutral OpenAI-wire layer (FEAT-438) that owns the wire protocol and declares no OpenAI-provider model defaults — to speak to Meta's Muse Spark model family (https://api.meta.ai/v1).

Chat Completions (ask/ask_stream/resume/invoke when use_responses=False) is inherited unchanged: it already funnels through OpenAIBaseClient._chat_completion(), and live testing confirmed the base's existing emissions are Meta-legal (tool_choice="auto" and max_tokens).

The Responses API path (use_responses=True, the default) is net-new and local to this class (design decision D1): OpenAIBaseClient has no Responses-API support by design, so ask()/ask_stream() are overridden here to route to :meth:MetaClient._responses_completion. The structure of :class:~parrot.clients.openai.OpenAIClient's equivalent methods (gpt.py:353-680) is mirrored as a read-only reference — never imported, subclassed, or modified; some duplication is the accepted, reversible trade.

See sdd/specs/meta-llm-client.spec.md (FEAT-526).

Alias AIMessage

Re-exported from parrot.models.AIMessage.

Alias AIMessageFactory

Re-exported from parrot.models.AIMessageFactory.

Alias CompletionUsage

Re-exported from parrot.models.CompletionUsage.

Class MetaClient

Client for Meta Model API (Muse Spark family).

Parameter Type Default Description
api_key str | None None Meta Model API key. Resolution order: api_key kwarg → META_API_KEY env var → MODEL_API_KEY env var. This chain MUST NOT fall through to OPENAI_API_KEY — the AsyncOpenAI SDK would otherwise silently pick that up and ship an OpenAI key to Meta.
base_url str | None None Override for Meta's API base URL. Defaults to https://api.meta.ai/v1.
use_responses bool True Whether to route ask()/ask_stream() through the Responses API (default) instead of the inherited Chat Completions funnel. Set False to use Chat Completions.
native_tool_search bool False Opt in to Meta's hosted tool_search instead of parrot's client-side search_tools (spec §3 Module 6, D2). When True, every function tool is sent with defer_loading: true (name and description stay visible, the parameter schema is withheld) plus {"type": "tool_search"}, and Meta searches and loads definitions in the same response. False by default: parrot's client-side path stays the default because the operator measured Meta's hosted tool_search as slower than parrot's own search — an operator measurement, not an independently reproduced benchmark. Responses API only; ask()/ask_stream() raise ValueError when combined with use_responses=False.
**kwargs Any {} Additional arguments passed to :class:~parrot.clients.openai_base.OpenAIBaseClient.

Attributes:

Attribute Type Description
client_type str
client_name str
provider_keys tuple[str, ...]
models type[MetaModel]

Method MetaClient.get_client

Initialize AsyncOpenAI configured for Meta Model API.

get_client() -> 'AsyncOpenAI'

Returns: 'AsyncOpenAI' — An AsyncOpenAI instance pointed at Meta's base URL, with the resolved Meta API key passed explicitly (never relying on the SDK's OPENAI_API_KEY default).

Raises:

  • ImportError — If the openai package is not installed.

Method MetaClient.list_models

List available models from Meta Model API.

Fetches the model catalog from GET /v1/models.

list_models() -> list[dict[str, Any]]

Returns: list[dict[str, Any]] — List of model dicts as returned by the endpoint's data key.

Raises:

  • aiohttp.ClientError — If the HTTP request fails.

Method MetaClient.count_input_tokens

Count input tokens for a prospective Responses API request.

Standalone endpoint (POST /v1/responses/input_tokens) — it does not depend on the generation path, only on the client's credentials and base URL, so it works regardless of self.use_responses.

count_input_tokens(*, model: str | None = None, input: Any, **kwargs: Any) -> int

Parameter Type Default Description
model str | None None Model to count for, or None to use the configured one.
input Any The Responses-shaped input payload to count tokens for.
**kwargs Any {} Additional args forwarded to the SDK call (e.g. instructions, tools).

Returns: int — The input token count.

Method MetaClient.ask

Ask Meta Model API a question, routing via use_responses.

When self.use_responses is False, delegates unchanged to the inherited Chat Completions funnel (:meth:~parrot.clients.openai_base.OpenAIBaseClient.ask). When True (the default), routes to the Responses API via :meth:_responses_completion, reusing the same generic tool-call loop (:meth:~parrot.clients.openai_base.OpenAIBaseClient._run_tool_call_loop) so a full tool-calling round trip works on both paths.

Keeps the base's signature exactly, plus the additive search_grounding keyword (spec §6/§7), so the funnel-parity sweep in tests/clients/test_openai_base_parity.py continues to pass.

When self.native_tool_search is True, function tools are deferred to Meta's hosted tool_search instead of parrot's client-side search_tools (whether or not lazy_loading is set); with nothing to defer, the call falls back to parrot's path. Loaded tools are reported in metadata["tool_search_calls"].

ask(prompt: str, model: Any | None = None, max_tokens: int | None = None, temperature: float | None = None, files: list[Any] | None = None, system_prompt: str | None = None, history: Any | None = None, structured_output: Any | None = None, tools: list[dict[str, Any]] | None = None, use_tools: bool | None = None, lazy_loading: bool = False, search_grounding: bool = False) -> AIMessage

Parameter Type Default Description
prompt str The prompt to send to the model.
model Any | None None The model to use, or None to use the configured one.
max_tokens int | None None Maximum output tokens (mapped to max_output_tokens on this path).
temperature float | None None Sampling temperature.
files list[Any] | None None Files to upload before the call.
system_prompt str | None None System prompt to prepend.
history Any | None None Already-rendered conversation history.
structured_output Any | None None Not yet supported on the Responses path; ignored when use_responses is True.
tools list[dict[str, Any]] | None None Tools to register for this call.
use_tools bool | None None Whether to use tools; defaults to self.enable_tools.
lazy_loading bool False If True, enable dynamic tool searching.
search_grounding bool False If True, inject Meta's native web-search tool ({"type": "web_search"}) into the Responses request, enabling live retrieval grounding. Opt-in and False by default — it triggers live web requests and bills for extra model iterations. Requires self.use_responses (Responses-API only); citation/ annotation extraction is explicitly NOT implemented — a verified-good grounded response returned empty annotations (spec §7 gotcha 5).

Returns: AIMessage — The response from the model.

Raises:

  • ValueError — If search_grounding=True or self.native_tool_search is set while self.use_responses is False.

Method MetaClient.ask_stream

Stream a response, routing via use_responses.

When self.use_responses is False, delegates unchanged to the inherited Chat Completions streaming funnel. When True (the default), streams text deltas from the Responses API.

ask_stream(prompt: str, model: Any | None = None, max_tokens: int | None = None, temperature: float | None = None, files: list[Any] | None = None, system_prompt: str | None = None, history: Any | None = None, tools: list[dict[str, Any]] | None = None, use_tools: bool = True, structured_output: Any | None = None, lazy_loading: bool = False, **kwargs: Any)

Parameter Type Default Description
prompt str
model Any | None None
max_tokens int | None None
temperature float | None None
files list[Any] | None None
system_prompt str | None None
history Any | None None
tools list[dict[str, Any]] | None None
use_tools bool True
structured_output Any | None None
lazy_loading bool False
**kwargs Any {}

Raises:

  • ValueError — If self.native_tool_search is set while self.use_responses is False.

Alias MetaModel

Re-exported from parrot.clients.meta.models.MetaModel.

Alias OpenAIBaseClient

Re-exported from parrot.clients.openai_base.OpenAIBaseClient.

Alias current_session_id

Re-exported from parrot.observability.context.current_session_id.

Alias current_user_id

Re-exported from parrot.observability.context.current_user_id.

Attribute logger

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally