TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/primeintellect-ai/verifiers/llms.txt
Use this file to discover all available pages before exploring further.
OpenAICompletionsClient class provides a wrapper around the OpenAI Completions API (legacy text completion endpoint) using the AsyncOpenAI client.
Overview
This client implements theClient interface for OpenAI’s legacy Completions API, which is used for text completion models. It handles:
- Message conversion to plain text format (Completions API only accepts text prompts)
- Text-only content validation (rejects images and other multimodal content)
- Token usage and logprobs parsing
- Context length error handling
Type Aliases
Class Definition
- ClientT:
AsyncOpenAI- The OpenAI async client - MessagesT:
OpenAITextMessages- Plain text string (concatenated messages) - ResponseT:
OpenAITextResponse- OpenAI Completion object - ToolT:
None- Tools are not supported
Constructor
Either a pre-configured
AsyncOpenAI client or a ClientConfig to create one.Example
Methods
setup_client
AsyncOpenAI client from a ClientConfig.
Configuration with API key, base URL, and other settings.
AsyncOpenAI instance.
close
AsyncOpenAI client connection.
to_native_prompt
List of Verifiers message objects. All messages will be concatenated with double newlines.
(text_prompt, extra_kwargs). The text prompt is a string with all message contents joined by "\n\n". The extra_kwargs dict is currently empty.
Raises:
ValueErrorif any message contains non-text content (e.g., images)
to_native_tool
A Verifiers tool definition.
ValueError with message “Tools are not supported for Completions API”
get_native_response
Plain text prompt string.
OpenAI model identifier (e.g.,
"gpt-3.5-turbo-instruct").Sampling parameters. None values are filtered out before sending to API.
Must be None or empty. Tools are not supported.
Completion object.
Raises:
ValueErrorif tools are providedOverlongPromptErrorif the prompt exceeds the model’s context length
raise_from_native_response
The OpenAI Completion response.
EmptyModelResponseErrorif response is None, has no choices, or the text is emptyInvalidModelResponseErrorif the response has more than 1 choice
from_native_response
Completion to a Verifiers Response.
The OpenAI Completion response.
Response object with:
id: Response ID from OpenAIcreated: Timestamp from OpenAImodel: Model name from responseusage: Token counts (prompt_tokens, completion_tokens, total_tokens, reasoning_tokens=0)message: Response message with text content and metadata
- Content: Text from
response.choices[0].text - Finish reason: Mapped from OpenAI values (
"stop"→"stop","length"→"length", others →None) - Is truncated:
Trueif finish_reason is"length" - Tokens: If available (vLLM with
return_tokens=true), includes prompt_token_ids, token_ids, logprobs - Reasoning content: Always
None(not supported by Completions API) - Tool calls: Always
None(not supported by Completions API)
Usage Example
Limitations
No Tool Support
No Multimodal Content
Token Details
The client attempts to parse token-level information from the response:Error Handling
The@handle_openai_overlong_prompt decorator catches BadRequestError and converts context length errors to OverlongPromptError. It detects phrases like:
- “this model’s maximum context length is”
- “is longer than the model’s context length”
- “prompt_too_long”
- “context length”
See Also
- OpenAIChatCompletionsClient - For chat models with tool support
- Client - Base client class
- ClientConfig - Configuration type
- Response - Response type