翻篇收录说明
翻篇网页快照

Text models - Fireworks AI Docs

https://docs.fireworks.ai/guides/querying-text-models

最近抓取:2026-12-04 03:36:08(北京时间)

最近内容变化:2026-12-01 00:56:30(北京时间)

这是最近一次有效抓取的文本快照,不含网页脚本、图片和动态交互内容。实际网页可能已更新。

访问原网页

页面简介

Query, track, and manage inference for text models on Fireworks with chat completions, streaming, tool use, and structured output via the OpenAI-compatible API.

正文摘录

New to Fireworks? Start with the Serverless Quickstart for a step-by-step guide to making your first API call. Fireworks provides fast, cost-effective access to leading open-source text models through OpenAI-compatible APIs. Query models via serverless inference or dedicated deployments using the chat completions API (recommended), completions API, or responses API. Browse 100+ available models → Chat Completions API Python (Fireworks SDK) Python (OpenAI SDK) JavaScript curlfrom fireworks import Fireworks client = Fireworks() response = client.chat.completions.create( model="accounts/fireworks/models/glm-5p3-flash", messages=[{"role": "user", "content": "Explain quantum computing in simple terms"}] ) print(response.choices[0].message.content) import os from openai import OpenAI client = OpenAI( api_key=os.environ.get("FIREWORKS_API_KEY"), base_url="https://api.fireworks.ai/inference/v1" ) response = client.chat.completions.create( model="accounts/fireworks/models/glm-5p3-flash", messages=[{ "role": "user", "content": "Explain quantum computing in simple terms" }] ) print(response.choices[0].message.content) import OpenAI from "openai"; const client = new OpenAI({ apiKey: process.env.FIREWORKS_API_KEY, baseURL: "https://api.fireworks.ai/inference/v1", }); const response = await client.chat.completions.create({ model: "accounts/fireworks/models/glm-5p3-flash", messages: [ { role: "user", content: "Explain quantum computing in simple terms", }, ], }); console.log(response.choices[0].message.content); curl https://api.fireworks.ai/inference/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $FIREWORKS_API_KEY" \ -d '{ "model": "accounts/fireworks/models/glm-5p3-flash", "messages": [ { "role": "user", "content": "Explain quantum computing in simple terms" } ] }' Most models automatically format your messages with the correct template. To verify the exact prompt used, enable the echo parameter. For Priority tier (service_tier: "priority"), Spot (service_tier: "spot"), Fast, and Ultra-fast, see Serverless Modes. Alternative query methods Fireworks also supports Completions API and Responses API. Querying dedicated deployments For consistent performance, guaranteed capacity, or higher throughput, you can query on-demand deployments instead of serverless models. Deployments use the same APIs with a deployment-specific identifier: accounts/<ACCOUNT_ID>/deployments/<DEPLOYMENT_ID> For example: response = client.chat.completions.create( model="accounts/<ACCOUNT_ID>/deployments/<DEPLOYMENT_ID>", messages=[{"role": "user", "content": "Hello"}] ) Common patterns Multi-turn conversations Maintain conversation history by including all previous messages: messages = [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "What's the capital of France?"}, {"role": "assistant", "content": "The capital of France is Paris."}, {"role": "user", "content": "What's its population?"} ] response = client.chat.completions.create( model="accounts/fireworks/models/glm-5p3-flash", messages=messages ) print(response.choices[0].message.content) The model uses the full conversation history to provide contextually relevant responses. System prompts Override the default system prompt by setting the first message with role: "system": messages = [ {"role": "system", "content": "You are a helpful Python expert who provides concise code examples."}, {"role": "user", "content": "How do I read a CSV file?"} ] response = client.chat.completions.create( model="accounts/fireworks/models/glm-5p3-flash", messages=messages ) To completely omit the system prompt, set the first message’s content to an empty string. Streaming responses Stream tokens as they’re generated for real time, interactive UX. Covered in detail in the Serverless Quickstart. stream = client.chat.completions.create( model="accounts/fireworks/models/glm-5p3-flash", messages=[{"role": "user", "content": "Tell me a story"}], stream=True ) for chunk in stream: if chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="") Aborting streams: Close the connection to stop generation and avoid billing for ungenerated tokens: for chunk in stream: print(chunk.choices[0].delta.content, end="") if some_condition: stream.close() break Async requests Use async clients to make multiple concurrent requests for better throughput: Python (Fireworks SDK) Python (OpenAI SDK) JavaScriptfrom fireworks import AsyncFireworks client = AsyncFireworks() async def main(): response = await client.chat.completions.create( model="accounts/fireworks/models/glm-5p3-flash", messages=[{"role": "user", "content": "Hello"}] ) print(response.choices[0].message.content) asyncio.run(main()) import asyncio from openai import AsyncOpenAI client = AsyncOpenAI( api_key=os.environ.get("FIREWORKS_API_KEY"), base_url="https://api.fireworks.ai/inference/v1" ) async def main(): response = await client.chat.completions.create( model="accounts/fireworks/models/glm-5p3-flash", messages=[{"role": "user", "content": "Hello"}] ) print(response.choices[0].message.content) asyncio.run(main()) import OpenAI from "openai"; const client = new OpenAI({ apiKey: process.env.FIREWORKS_API_KEY, baseURL: "https://api.fireworks.ai/inference/v1", }); async function main() { const response = await client.chat.completions.create({ model: "accounts/fireworks/models/glm-5p3-flash", messages: [{ role: "user", content: "Hello" }], }); console.log(response.choices[0].message.content); } main(); Usage & performance tracking Every response includes token usage information and performance metrics for debugging and observability. For aggregate metrics over time, see the usage dashboard. The analytics and usage dashboard measures server-acknowledged requests, not every client-observed outcome.The dashboard counts requests that successfully reached the Fireworks API. It does not capture connection timeouts before the request lands on the server, client-side retries before a successful attempt, or failures on the network path between your application and the API.If your application reports failures but the dashboard looks healthy, check client timeout configuration and network connectivity. For dedicated deployments, Prometheus-style metrics reflect server-side behavior for that deployment. Token usage (prompt, completion, total tokens) is included in the response body for all requests. Performance metrics (latency, time-to-first-token, etc.) are included in response headers for non-streaming requests. For streaming requests, use the perf_metrics_in_response parameter to include all metrics in the response body. Non-streaming Streaming (usage only) Streaming (with performance metrics)response = client.chat.completions.create( model="accounts/fireworks/models/glm-5p3-flash", messages=[{"role": "user", "content": "Hello"}] ) # Token usage (always included) print(response.usage.prompt_tokens) # Tokens in your prompt print(response.usage.completion_tokens) # Tokens generated print(response.usage.total_tokens) # Total tokens billed # Performance metrics are in response headers: # fireworks-prompt-tokens, fireworks-server-time-to-first-token, etc. stream = client.chat.completions.create( model="accounts/fireworks/models/glm-5p3-flash", messages=[{"role": "user", "content": "Hello"}], stream=True ) for chunk in stream: if chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="") # Usage is included in the final chunk if chunk.usage: print(f"\n\nTokens used: {chunk.usage.total_tokens}") print(f"Prompt: {chunk.usage.prompt_tokens}, Completion: {chunk.usage.completion_tokens}") stream = client.chat.completions.create( model="accounts/fireworks/models/glm-5p3-flash", messages=[{"role": "user", "content": "Hello, world!"}], stream=True, extra_body={"perf_metrics_in_response": True} ) for chunk in stream: if chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="") # Both usage and performance metrics are in the final chunk if chunk.choices[0].finish_reason: if chunk.usage: print(f"\n\nTokens: {chunk.usage.total_tokens}") if hasattr(chunk, 'perf_metrics'): print(f"Performance: {chunk.perf_metrics}") Usage information is automatically included in the final chunk for streaming responses (the chunk with finish_reason set). This is a Fireworks extension - OpenAI SDK doesn’t return usage for streaming by default. For all available metrics and details, see the API reference documentation. If you encounter errors during inference, see Inference Error Codes for common issues and resolutions. Advanced capabilities Extend text models with additional features for structured outputs, tool integration, and performance optimization: Tool callingConnect models to external tools and APIs with type-safe parametersStructured outputsEnforce JSON schemas for reliable data extractionResponses APIMulti-step reasoning for complex problem-solvingPredicted outputsSpeed up edits by predicting unchanged sectionsPrompt cachingCache common prompts to reduce latency and costBatch inferenceProcess large volumes of requests asynchronously Configuration & debugging Sampling parametersControl how the model generates text. Fireworks automatically uses recommended sampling parameters from each model’s HuggingFace generation_config.json when you don’t specify them explicitly, ensuring optimal performance out-of-the-box.We pull temperature, top_k, top_p, min_p, and typical_p from the model’s configuration when not explicitly provided.TemperatureAdjust randomness (0 = deterministic, higher = more creative):response = client.chat.completions.create( model="accounts/fireworks/models/glm-5p3-flash", messages=[{"role": "user", "content": "Write a poem"}], temperature=0.7 # Override model default ) Max tokensControl the maximum number of tokens in the generated completion:max_tokens=100 # Generate at most 100 tokens Important notes: Default value is 2048 tokens if not specified Most models support u