### Call A4F API using Python Source: https://www.a4f.co/docs/quickstart This example shows how to interact with the A4F API for chat completions using Python. It requires the 'requests' library and demonstrates setting up the API endpoint, headers, and the JSON payload for the request. ```python import requests url = "https://api.a4f.co/v1/chat/completions" headers = { "Authorization": "Bearer YOUR_A4F_API_KEY", "Content-Type": "application/json" } data = { "model": "provider-1/chatgpt-4o-latest", "messages": [ {"role": "user", "content": "What is the meaning of life?"} ] } response = requests.post(url, headers=headers, json=data) print(response.json()) ``` -------------------------------- ### Call A4F API using TypeScript Source: https://www.a4f.co/docs/quickstart This TypeScript example illustrates how to send a chat completion request to the A4F API. It utilizes the 'fetch' API to make the POST request, including the authorization header and the JSON body with the model and message. ```typescript async function getChatCompletion() { const response = await fetch("https://api.a4f.co/v1/chat/completions", { method: "POST", headers: { "Authorization": "Bearer YOUR_A4F_API_KEY", "Content-Type": "application/json" }, body: JSON.stringify({ "model": "provider-1/chatgpt-4o-latest", "messages": [ {"role": "user", "content": "What is the meaning of life?"} ] }) }); const data = await response.json(); console.log(data); } getChatCompletion(); ``` -------------------------------- ### Install OpenAI Python SDK Source: https://www.a4f.co/docs/index Installs the OpenAI SDK for Python using pip. This is a prerequisite for integrating with A4F using Python, as A4F is compatible with the OpenAI API specification. ```bash pip install openai ``` -------------------------------- ### Install OpenAI JavaScript SDK Source: https://www.a4f.co/docs/index Installs the OpenAI SDK for JavaScript using npm. This is necessary for integrating with A4F using JavaScript, leveraging its compatibility with the OpenAI API. ```bash npm install openai ``` -------------------------------- ### Node.js Axios Example for A4F API Source: https://www.a4f.co/docs/guides/third-party-sdks Shows how to interact with the A4F API using Node.js and the `axios` library. This example configures the API key, base URL, and sends a chat completion request. It includes comprehensive error handling for various network and API response issues. ```javascript import axios from 'axios'; const A4F_API_KEY: string = process.env.A4F_API_KEY || "YOUR_A4F_API_KEY"; const A4F_BASE_URL: string = "https://api.a4f.co/v1"; async function callA4FWithAxios() { const headers = { "Authorization": `Bearer ${A4F_API_KEY}`, "Content-Type": "application/json", }; const payload = { model: "provider-3/claude-3-haiku-20240307", // Use an A4F provider-prefixed model messages: [ { role: "user", content: "Hello from Node.js with axios!" } ] }; try { const response = await axios.post(`${A4F_BASE_URL}/chat/completions`, payload, { headers }); console.log(response.data.choices[0].message.content); } catch (error: any) { console.error("Error calling A4F API with axios:"); if (error.response) { console.error("Status:", error.response.status); console.error("Data:", error.response.data); } else if (error.request) { console.error("No response received:", error.request); } else { console.error("Error setting up request:", error.message); } } } callA4FWithAxios(); ``` -------------------------------- ### Install OpenAI SDK (Python & Node.js) Source: https://www.a4f.co/docs/guides/openai-sdk Installs the OpenAI SDK for Python using pip and for Node.js using npm. These are prerequisites for using the OpenAI client libraries with A4F. ```python pip install openai ``` ```bash npm install openai ``` -------------------------------- ### Example API Request JSON Source: https://www.a4f.co/docs/responses Demonstrates the structure of a typical request to the API, including model selection, user input, and generation instructions. ```json { "model": "provider-5/gpt-5.1-codex", "input": [ { "role": "user", "content": "Analyze the correlation between user engagement and feature adoption." } ], "instructions": "You are a data analyst. Provide step-by-step reasoning before your final answer.", "max_tokens": 1024, "temperature": 0.5 } ``` -------------------------------- ### Node.js (axios) Example Source: https://www.a4f.co/docs/guides/third-party-sdks Demonstrates how to make a chat completion request to the A4F API using Node.js and the `axios` library. ```APIDOC ## POST /v1/chat/completions ### Description Sends a chat message to the A4F API to get a completion using Node.js and axios. ### Method POST ### Endpoint https://api.a4f.co/v1/chat/completions ### Parameters #### Headers - **Authorization** (string) - Required - Bearer token for authentication (e.g., `Bearer YOUR_A4F_API_KEY`). - **Content-Type** (string) - Required - Must be `application/json`. #### Request Body - **model** (string) - Required - The A4F provider-prefixed model ID (e.g., `provider-3/claude-3-haiku-20240307`). - **messages** (array) - Required - An array of message objects, each with a `role` (`user`, `assistant`, `system`) and `content` (string). ### Request Example ```json { "model": "provider-3/claude-3-haiku-20240307", "messages": [ { "role": "user", "content": "Hello from Node.js with axios!" } ] } ``` ### Response #### Success Response (200) - **choices** (array) - An array of completion choices. - **message** (object) - The message object from the assistant. - **content** (string) - The content of the assistant's reply. #### Response Example ```json { "id": "chatcmpl-456", "object": "chat.completion", "created": 1700000001, "model": "provider-3/claude-3-haiku-20240307", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "Hi there! What can I assist you with?" }, "logprobs": null, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 12, "completion_tokens": 18, "total_tokens": 30 } } ``` ``` -------------------------------- ### Python (requests library) Example Source: https://www.a4f.co/docs/guides/third-party-sdks Demonstrates how to make a chat completion request to the A4F API using Python's `requests` library. ```APIDOC ## POST /v1/chat/completions ### Description Sends a chat message to the A4F API to get a completion. ### Method POST ### Endpoint https://api.a4f.co/v1/chat/completions ### Parameters #### Headers - **Authorization** (string) - Required - Bearer token for authentication (e.g., `Bearer YOUR_A4F_API_KEY`). - **Content-Type** (string) - Required - Must be `application/json`. #### Request Body - **model** (string) - Required - The A4F provider-prefixed model ID (e.g., `provider-1/chatgpt-4o-latest`). - **messages** (array) - Required - An array of message objects, each with a `role` (`user`, `assistant`, `system`) and `content` (string). ### Request Example ```json { "model": "provider-1/chatgpt-4o-latest", "messages": [ {"role": "user", "content": "Hello from Python requests!"} ] } ``` ### Response #### Success Response (200) - **choices** (array) - An array of completion choices. - **message** (object) - The message object from the assistant. - **content** (string) - The content of the assistant's reply. #### Response Example ```json { "id": "chatcmpl-123", "object": "chat.completion", "created": 1700000000, "model": "provider-1/chatgpt-4o-latest", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "Hello! How can I help you today?" }, "logprobs": null, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 10, "completion_tokens": 20, "total_tokens": 30 } } ``` ``` -------------------------------- ### Example API Response JSON Source: https://www.a4f.co/docs/responses Illustrates a successful API response, showcasing the separation of reasoning steps and the final assistant message, along with usage statistics. ```json { "id": "resp_abc123def456", "object": "response", "created_at": 1729584251, "model": "provider-5/gpt-5.1-codex", "output": [ { "id": "reasoning_1", "type": "reasoning", "content": [ "Step 1: Acknowledge the user's request to find a correlation.", "Step 2: Formulate a plan to analyze the data.", "Step 3: Perform the correlation calculation.", "Step 4: Structure the final answer as a JSON object." ], "summary": [ "User wants correlation analysis. I will outline steps and provide final JSON output." ] }, { "id": "msg_xyz789", "type": "message", "role": "assistant", "content": [ { "type": "output_text", "text": "{\"correlation_factor\": 0.82, \"summary\": \"Strong positive correlation found...\"}", "annotations": [], "logprobs": [] } ], "status": "completed" } ], "usage": { "prompt_tokens": 56, "completion_tokens": 121, "total_tokens": 177 } } ``` -------------------------------- ### POST /v1/chat/completions (Node.js) Source: https://www.a4f.co/docs/guides/api-direct Example of calling the A4F chat completions endpoint using Node.js native fetch. ```APIDOC ## POST /v1/chat/completions ### Description Initiates a chat completion request to the A4F API, allowing for conversational AI interactions. ### Method POST ### Endpoint https://api.a4f.co/v1/chat/completions ### Parameters #### Headers - **Authorization** (string) - Required - Bearer token for authentication. - **Content-Type** (string) - Required - Must be `application/json`. #### Request Body - **model** (string) - Required - The A4F provider-prefixed model ID to use (e.g., `provider-3/claude-3-haiku-20240307`). - **messages** (array) - Required - An array of message objects, each with a `role` (`system`, `user`, or `assistant`) and `content`. - **temperature** (number) - Optional - Controls randomness; values between 0 and 2. - **max_tokens** (integer) - Optional - The maximum number of tokens to generate. - **stream** (boolean) - Optional - Set to `true` to enable streaming responses. ### Request Example ```json { "model": "provider-3/claude-3-haiku-20240307", "messages": [ { "role": "system", "content": "You are an expert historian."}, { "role": "user", "content": "Briefly explain the significance of the Rosetta Stone."} ], "temperature": 0.5, "max_tokens": 150 } ``` ### Response #### Success Response (200) - **id** (string) - Unique identifier for the completion. - **model** (string) - The model used for the completion. - **choices** (array) - An array of completion choices. Each choice contains: - **message** (object) - The assistant's message, with `role` and `content`. - **finish_reason** (string) - The reason the completion finished (e.g., `stop`, `length`). - **usage** (object) - Token usage information (`prompt_tokens`, `completion_tokens`, `total_tokens`). #### Response Example ```json { "id": "chatcmpl-123", "model": "provider-3/claude-3-haiku-20240307", "choices": [ { "message": { "role": "assistant", "content": "The Rosetta Stone is significant because it provided the key to deciphering ancient Egyptian hieroglyphs..." }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 30, "completion_tokens": 50, "total_tokens": 80 } } ``` ``` -------------------------------- ### Langchain Configuration (Conceptual) Source: https://www.a4f.co/docs/guides/third-party-sdks Conceptual example of configuring Langchain's `ChatOpenAI` class to use A4F by overriding the API base URL and key. ```APIDOC ## Langchain Integration ### Description This section provides a conceptual example of how to configure Langchain's `ChatOpenAI` class to interact with A4F by specifying a custom API base URL and API key. ### Method N/A (Configuration within a framework) ### Endpoint N/A (Framework handles endpoint internally, but points to A4F's base URL) ### Parameters When initializing `ChatOpenAI` or a similar class in Langchain, look for parameters like: - **openai_api_base** (string) - Set this to `https://api.a4f.co/v1`. - **openai_api_key** (string) - Set this to your A4F API key. - **model_name** (string) - Use an A4F provider-prefixed model ID (e.g., `provider-1/gpt-4-turbo`). ### Request Example (Conceptual Python Code) ```python from langchain_openai import ChatOpenAI import os A4F_API_KEY = os.getenv("A4F_API_KEY", "YOUR_A4F_API_KEY") A4F_BASE_URL = "https://api.a4f.co/v1" llm = ChatOpenAI( openai_api_base=A4F_BASE_URL, openai_api_key=A4F_API_KEY, model_name="provider-1/gpt-4-turbo", # Example A4F model temperature=0.7 ) # Example usage: # response = llm.invoke("Translate 'hello world' to French.") # print(response.content) ``` ### Response #### Success Response (Framework Dependent) Langchain's `ChatOpenAI` typically returns a `AIMessage` object containing the completion content. #### Response Example (Conceptual) ``` AIMessage(content='Bonjour le monde') ``` ``` -------------------------------- ### A4F API cURL Example Source: https://www.a4f.co/docs/api-overview This cURL command demonstrates how to make a chat completions request to the A4F API, including the necessary authorization and content-type headers. ```bash curl https://api.a4f.co/v1/chat/completions \ -H "Authorization: Bearer YOUR_A4F_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "provider-1/chatgpt-4o-latest", "messages": [{"role": "user", "content": "Hello!"}] }' ``` -------------------------------- ### Basic Chat Completion with A4F (Python & cURL) Source: https://www.a4f.co/docs/guides/openai-sdk Demonstrates how to perform a basic chat completion request using the configured OpenAI client in Python and via a cURL command. Both examples show specifying a model with the A4F provider prefix. ```python completion = client.chat.completions.create( model="provider-1/chatgpt-4o-latest", messages=[ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "What is the capital of France?"} ], temperature=0.7, max_tokens=50 ) print(completion.choices[0].message.content) ``` ```bash curl https://api.a4f.co/v1/chat/completions \ -H "Authorization: Bearer YOUR_A4F_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "provider-1/chatgpt-4o-latest", "messages": [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "What is the capital of France?"} ], "temperature": 0.7, "max_tokens": 50 }' ``` -------------------------------- ### Generate Video from Text Prompt (cURL) Source: https://www.a4f.co/docs/api-reference/video-generation Example of how to generate a video using the A4F API's video generation endpoint via cURL. It specifies the model, prompt, quality, duration, and aspect ratio. ```curl curl https://api.a4f.co/v1/video/generations \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $A4F_API_KEY" \ -d '{ "model": "provider-2/kling-v2.1", "prompt": "A cinematic drone shot of waves crashing against a cliff at sunset, 4k, photorealistic", "quality": "1080p", "duration": 5, "ratio": "16:9" }' ``` -------------------------------- ### Transcribe Audio using cURL Source: https://www.a4f.co/docs/api-reference/audio-transcriptions This example demonstrates how to transcribe an audio file using the cURL command-line tool. It requires the audio file path and the desired transcription model. The response includes the transcribed text and audio duration. ```shell curl https://api.a4f.co/v1/audio/transcriptions \ -H "Authorization: Bearer YOUR_A4F_API_KEY" \ -F file=@/path/to/your/audio.mp3 \ -F model="provider-3/whisper-1" ``` -------------------------------- ### Basic A4F Chat Completion Request with cURL Source: https://www.a4f.co/docs/index Shows a basic example of making a chat completion request to the A4F API using cURL. It includes setting the API key in the Authorization header and providing the model and messages. ```bash export A4F_API_KEY="your_actual_api_key_here" curl https://api.a4f.co/v1/chat/completions \ -H "Authorization: Bearer $A4F_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "provider-1/chatgpt-4o-latest", "messages": [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Explain the concept of API gateways."} ], "temperature": 0.7, "max_tokens": 150 }' ``` -------------------------------- ### Configure Codeium with A4F Source: https://www.a4f.co/docs/mcp-tools/others Configuration for Codeium to connect to A4F's API. This setup is typically for enterprise users and requires specifying the API provider as 'openai-compatible', along with the base URL, API key, and desired model. ```json { "api": { "provider": "openai-compatible", "baseUrl": "https://api.a4f.co/v1", "apiKey": "YOUR_A4F_API_KEY", "model": "provider-1/chatgpt-4o-latest" }, "features": { "codeCompletion": true, "chatAssistant": true, "codeExplanation": true } } ``` -------------------------------- ### Configure LangChain Python with A4F Source: https://www.a4f.co/docs/mcp-tools/others Example of configuring the LangChain Python framework to use A4F's API. This involves initializing the ChatOpenAI class with A4F's model, API key, and API base URL, and then using it within LangChain chains. ```python from langchain_openai import ChatOpenAI # Configure LangChain to use A4F llm = ChatOpenAI( model="provider-1/chatgpt-4o-latest", openai_api_key="YOUR_A4F_API_KEY", openai_api_base="https://api.a4f.co/v1", temperature=0.7 ) # Use with LangChain chains from langchain.chains import LLMChain from langchain.prompts import PromptTemplate prompt = PromptTemplate( input_variables=["question"], template="Answer the following question: {question}" ) chain = LLMChain(llm=llm, prompt=prompt) response = chain.run("What is machine learning?") ``` -------------------------------- ### JSON Example Error Response from A4F API Source: https://www.a4f.co/docs/errors Provides an example of a JSON error response from the A4F API. This illustrates the structure defined in the TypeScript interfaces, showing how error details are presented. ```json { "error": { "message": "Invalid API key provided. You may be trying to use a key with insufficient permissions.", "type": "invalid_request_error", "param": null, "code": "authentication_error" } } ``` -------------------------------- ### Setup A4F Client and Messages for Tool Calling (Python) Source: https://www.a4f.co/docs/tool-calling Initializes the OpenAI client with A4F API base URL and key, and sets up system and user messages for an LLM interaction. This is the first step in enabling tool calling capabilities with A4F. ```python from openai import OpenAI MODEL = "provider-3/openai/gpt-4o" and model known for tool calling a4f_client = OpenAI( base_url="https://api.a4f.co/v1", api_key="YOUR_A4F_API_KEY", # Replace with your actual A4F API key ) task = "What are the titles of some James Joyce books?" messages = [ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": task, } ] ``` -------------------------------- ### Get Usage Statistics with Python Requests Source: https://www.a4f.co/docs/api-reference/get-usage This snippet shows how to fetch usage statistics using the Python Requests library. It includes setting up the Authorization header and optionally specifying sections to retrieve. ```python import requests api_key = "YOUR_A4F_API_KEY" url = "https://api.a4f.co/v1/usage" headers = { "Authorization": f"Bearer {api_key}" } params = { "section": "account_information,rate_limits_and_restrictions" } response = requests.get(url, headers=headers, params=params) if response.status_code == 200: print(response.json()) else: print(f"Error: {response.status_code}") print(response.text) ``` -------------------------------- ### Get Usage Statistics Source: https://www.a4f.co/docs/api-reference/get-usage Retrieve detailed usage statistics for your A4F API key. This endpoint provides insights into your account information, subscription status, rate limits, token consumption, and model-specific usage. ```APIDOC ## GET /v1/usage ### Description Retrieve detailed usage statistics for your A4F API key. This endpoint provides insights into your account information, subscription status, rate limits, token consumption, and model-specific usage. ### Method GET ### Endpoint /v1/usage ### Headers #### Authorization - **Authorization** (string) - Required - Bearer token for authentication. Your A4F API key. Example: `Bearer ddc-a4f-xxxxxxxx`. ### Query Parameters #### section - **section** (string) - Optional - A comma-separated list of sections to include in the response. If omitted, all sections are returned. Valid sections are: `account_information`, `subscription_details`, `billing_information`, `rate_limits_and_restrictions`, `usage_statistics`, `model_specific_usage`. ### Response #### Success Response (200 OK) - **account_information** (object) - Details about your account. - **username** (string) - Your username or display name. - **current_plan** (string) - Your current subscription plan (e.g., 'free', 'basic', 'pro'). - **is_enabled** (boolean) - Whether your API key is currently active. - **api_key** (string) - Your full API key. - **node_id** (string) - Your GitHub node ID or equivalent identifier. - **model_specific_usage** (object) - An object where keys are model IDs and values are usage statistics for that model. - **subscription_details** (object) - Information about your current subscription. - **creation_date** (string (ISO 8601)) - Date your API key was created. - **total_validity_days** (integer) - Total validity period of your current plan in days (-999999 for unlimited). - **effective_days_remaining** (integer) - Remaining days in your current plan's validity. - **plan_activation_history** (array of objects) - History of plan activations. - **billing_information** (object) - Summary of billing. - **payment_transactions** (array) - A list of payment amounts. - **total_amount_paid_usd** (number) - Total amount paid in USD. - **cumulative_cost_usd** (number) - Estimated cumulative cost of all usage in USD. - **rate_limits_and_restrictions** (object) - Your current API rate limits. - **requests_per_minute_limit** (integer) - Requests Per Minute (RPM) limit. - **requests_per_minute_remaining** (integer | string) - Remaining requests for the current minute. - **requests_per_day_limit** (integer) - Requests Per Day (RPD) limit. - **requests_per_day_remaining** (integer | string) - Remaining requests for the current day. - **model_whitelist** (object | string) - Your specific model whitelist, if configured. - **model_blacklist** (object | string) - Your specific model blacklist, if configured. - **usage_statistics** (object) - Aggregated usage statistics. - **overall_request_counts** (object) - Breakdown of request counts by type. - **token_consumption** (object) - Breakdown of token counts by type (chat, embedding, etc.). - **image_consumption** (object) - Statistics on generated images. ### Request Example ```json { "example": "curl \"https://api.a4f.co/v1/usage?section=account_information,rate_limits_and_restrictions\" \ -H \"Authorization: Bearer YOUR_A4F_API_KEY\"" } ``` ### Response Example ```json { "example": "{ \"account_information\": {\n \"username\": \"user123\",\n \"current_plan\": \"pro\",\n \"is_enabled\": true,\n \"api_key\": \"ddc-a4f-xxxxxxxx\",\n \"node_id\": \"node-abc-123\"\n },\n \"rate_limits_and_restrictions\": {\n \"requests_per_minute_limit\": 100,\n \"requests_per_minute_remaining\": 95,\n \"requests_per_day_limit\": 1000,\n \"requests_per_day_remaining\": 980,\n \"model_whitelist\": \"gpt-4,claude-3\",\n \"model_blacklist\": null\n }\n }" } ``` ``` -------------------------------- ### Get Usage Statistics with cURL Source: https://www.a4f.co/docs/api-reference/get-usage This snippet demonstrates how to retrieve usage statistics using cURL. It requires an Authorization header with your A4F API key and allows filtering response sections via query parameters. ```bash curl "https://api.a4f.co/v1/usage?section=account_information,rate_limits_and_restrictions" \ -H "Authorization: Bearer YOUR_A4F_API_KEY" ``` -------------------------------- ### List Available Models with cURL Source: https://www.a4f.co/docs/api-reference/list-models This example demonstrates how to retrieve a list of available AI models using a cURL request. It shows how to specify query parameters like 'plan', 'pricing', and 'features' to filter and enrich the response data. Ensure you replace 'YOUR_A4F_API_KEY' with your actual API key. ```bash curl "https://api.a4f.co/v1/models?plan=pro&pricing&features" \ -H "Authorization: Bearer YOUR_A4F_API_KEY" ``` -------------------------------- ### Initialize Langchain ChatOpenAI Client Directly with A4F Credentials Source: https://www.a4f.co/docs/guides/third-party-sdks This snippet shows an alternative method to configure Langchain's `ChatOpenAI` client by passing the A4F API key and base URL directly as arguments during initialization. This approach offers more explicit control over the client's configuration. ```python from langchain_openai import ChatOpenAI llm = ChatOpenAI( openai_api_key=os.getenv("A4F_API_KEY", "YOUR_A4F_API_KEY"), openai_api_base="https://api.a4f.co/v1", model_name="provider-1/chatgpt-4o-latest" # Use A4F provider-prefixed model ID ) ``` -------------------------------- ### Conceptual A4F Custom Headers Examples Source: https://www.a4f.co/docs/guides/headers This section provides conceptual examples of A4F-specific custom headers that might be used for advanced functionalities like caching control, metadata passthrough, and routing hints. These are illustrative and may not be currently implemented or may have different names/functionality. Always consult the official A4F API documentation for supported headers. ```text # These are conceptual examples and may not be currently implemented # or may have different names/functionality. # Always refer to the latest official A4F documentation. X-A4F-Cache-Control: read-write # Example: For controlling cache behavior X-A4F-Metadata-UserID: your-app-user-id-123 # Example: For passing end-user identifiers X-A4F-Route-Preference: latency # Example: For hinting routing preference ``` -------------------------------- ### POST /v1/chat/completions (cURL) Source: https://www.a4f.co/docs/guides/api-direct Example of calling the A4F chat completions endpoint using cURL. ```APIDOC ## POST /v1/chat/completions ### Description Initiates a chat completion request to the A4F API using cURL. ### Method POST ### Endpoint https://api.a4f.co/v1/chat/completions ### Parameters #### Headers - **Authorization** (string) - Required - Bearer token for authentication. - **Content-Type** (string) - Required - Must be `application/json`. #### Request Body - **model** (string) - Required - The A4F provider-prefixed model ID to use (e.g., `provider-1/chatgpt-4o-latest`). - **messages** (array) - Required - An array of message objects, each with a `role` (`user`) and `content`. - **temperature** (number) - Optional - Controls randomness; values between 0 and 2. ### Request Example ```bash export A4F_API_KEY="YOUR_A4F_API_KEY" curl -X POST https://api.a4f.co/v1/chat/completions \ -H "Authorization: Bearer $A4F_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "provider-1/chatgpt-4o-latest", "messages": [ {"role": "user", "content": "Translate 'Hello, world!' to Spanish."} ], "temperature": 0.3 }' ``` ``` -------------------------------- ### Call A4F API using cURL Source: https://www.a4f.co/docs/quickstart This snippet demonstrates how to make a chat completion request to the A4F API using cURL. It includes the necessary headers for authorization and content type, along with the request body specifying the model and user message. ```curl curl https://api.a4f.co/v1/chat/completions \ -H "Authorization: Bearer YOUR_A4F_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "provider-1/chatgpt-4o-latest", "messages": [ {"role": "user", "content": "What is the meaning of life?"} ] }' ```