Calling Inferway with the Anthropic SDK via /v1/messages
Connect to Inferway /v1/messages using standard Anthropic Python and Node SDKs by changing base_url.
Endpoint and authentication
Inferway provides an Anthropic Messages-compatible endpoint at /v1/messages. When using the Anthropic SDK, set base_url to https://api.inferway.ai (the SDK automatically appends /v1/messages).
Provide your Inferway API key as the apiKey argument (sent via the x-api-key or Authorization Bearer header). The gateway requires the standard anthropic-version header set to 2023-06-01, which the SDK attaches automatically.
Python SDK example
Using the standard anthropic Python SDK:
# Initialize Anthropic client: point base_url to Inferway API import os from anthropic import Anthropic client = Anthropic( base_url='https://api.inferway.ai', api_key=os.environ['INFERWAY_API_KEY'], ) # Send a streaming Messages request with client.messages.stream( model='your-model-id', max_tokens=1024, messages=[{'role': 'user', 'content': 'Hello!'}], ) as stream: for text in stream.text_stream: print(text, end='', flush=True) print()
Node SDK example
Using the standard @anthropic-ai/sdk Node SDK:
import Anthropic from '@anthropic-ai/sdk'; const client = new Anthropic({ baseURL: 'https://api.inferway.ai', apiKey: process.env.INFERWAY_API_KEY, }); const stream = await client.messages.create({ model: 'your-model-id', max_tokens: 1024, messages: [{ role: 'user', content: 'Hello!' }], stream: true, }); for await (const chunk of stream) { if (chunk.type === 'content_block_delta' && chunk.delta.type === 'text_delta') { process.stdout.write(chunk.delta.text); } } process.stdout.write('\n');
Parameter compatibility and differences
Supported parameters on /v1/messages: model (an available model ID from /models), messages (user and assistant turns with text and base64 image blocks), max_tokens (required by the Messages protocol), stream (SSE event streaming), system (system instructions), temperature, top_p, stop_sequences, tools (custom tool definitions with name, description, and input_schema), and tool_choice.
Reasoning controls: thinking is accepted. thinking.type set to enabled or adaptive turns the model's thinking on, and thinking.type set to disabled turns it off; budget_tokens and display are validated but do not size the reasoning. output_config.effort (low|medium|high|xhigh|max, default high) only sets how strong the thinking is once it is on: a request without thinking does not think, whatever its effort, so adding effort alone does not turn thinking on and removing thinking turns it off. output_config accepts no other key. Thinking blocks are not returned in the response, and reasoning tokens are billed. Unsupported and rejected parameters: cache_control (prompt caching), service_tier, mcp_servers, and container are rejected at request dispatch time. Hosted tool types (including web_search_, code_execution_, computer_, memory_, text_editor_, and bash_) are not available on this endpoint; client-defined tools are supported.